Использование php -a
$url = "https://getcomposer.org/versions";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
echo curl_exec($ch);
< /code>
он работает нормально, возвращает строку JSON из URL. Теперь продолжение в PHP -A взаимодействие терминала:
echo file_get_contents($url);
... после долгого ожидания, скажем: "ПРЕДУПРЕЖДЕНИЕ PHP: file_get_contents (...): Не удалось открыть потоки: подключение, временное в коде оболочки PHP" .error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set("auto_detect_line_endings","0");
ini_set("allow_url_fopen", "1");
ini_set("allow_url_include", "0");
ini_set("user_agent", "Mozilla/5.0");
echo file_get_contents($url);
// ---------------------
// Same (not work!) when using $context, as @sammitch's first try-answer:
$opts = [
'http' => [ 'user_agent' => 'Mozilla/5.0' ],
'https' => [ 'user_agent' => 'Mozilla/5.0' ]
];
$context = stream_context_create($opts);
echo file_get_contents($url,false,$context);
< /code>
ps: мне нужен file_get_contents для WordPress, композитора и т. Д. Этот вопрос о «почему file_get_contents не работает».php -v
PHP 8.0.30 (cli) (built: May 20 2025 13:31:19) ( NTS gcc x86_64 )
cat /etc/oracle-release
Oracle Linux Server release 9.6
< /code>
Подробнее от php -i | grep :
((grep -i "http"))
Registered PHP Streams => https, ftps, compress.zlib, php, file, glob, data, http, ftp, compress.bzip2, phar, zip
HTTP2 => Yes
HTTPS_PROXY => Yes
Protocols => dict, file, ftp, ftps, gopher, gophers, http, https, imap, imaps, ldap, ldaps, mqtt, pop3, pop3s, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp
HTTP input encoding translation => disabled
mbstring.http_input => no value => no value
mbstring.http_output => no value => no value
mbstring.http_output_conv_mimetypes => ^(text/|application/xhtml\+xml) => ^(text/|application/xhtml\+xml)
session.cookie_httponly => no value => no value
https_proxy => http://proxy.myIntranet:8080
http_proxy => http://proxy.myIntranet:8080
$_SERVER['https_proxy'] => http://proxy.myIntranet:8080
$_SERVER['http_proxy'] => http://proxy.myIntranet:8080
((grep -i "url"))
/etc/php.d/20-curl.ini,
allow_url_fopen => On => On
allow_url_include => Off => Off
curl
cURL support => enabled
cURL Information => 7.76.1
curl.cainfo => no value => no value
url_rewriter.hosts => no value => no value
url_rewriter.tags => form= => form=
Подробнее здесь: https://stackoverflow.com/questions/797 ... -to-enable
PHP-CLI работает с curl_init, но не с file_get_contents, как включить? ⇐ Php
Кемеровские программисты php общаются здесь
1758545557
Anonymous
Использование php -a
$url = "https://getcomposer.org/versions";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
echo curl_exec($ch);
< /code>
он работает нормально, возвращает строку JSON из URL. Теперь продолжение в PHP -A взаимодействие терминала:
echo file_get_contents($url);
... после долгого ожидания, скажем: "ПРЕДУПРЕЖДЕНИЕ PHP: file_get_contents (...): Не удалось открыть потоки: подключение, временное в коде оболочки PHP" .error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set("auto_detect_line_endings","0");
ini_set("allow_url_fopen", "1");
ini_set("allow_url_include", "0");
ini_set("user_agent", "Mozilla/5.0");
echo file_get_contents($url);
// ---------------------
// Same (not work!) when using $context, as @sammitch's first try-answer:
$opts = [
'http' => [ 'user_agent' => 'Mozilla/5.0' ],
'https' => [ 'user_agent' => 'Mozilla/5.0' ]
];
$context = stream_context_create($opts);
echo file_get_contents($url,false,$context);
< /code>
ps: мне нужен file_get_contents для WordPress, композитора и т. Д. Этот вопрос о «почему file_get_contents не работает».php -v
PHP 8.0.30 (cli) (built: May 20 2025 13:31:19) ( NTS gcc x86_64 )
cat /etc/oracle-release
Oracle Linux Server release 9.6
< /code>
Подробнее от php -i | grep :
((grep -i "http"))
Registered PHP Streams => https, ftps, compress.zlib, php, file, glob, data, http, ftp, compress.bzip2, phar, zip
HTTP2 => Yes
HTTPS_PROXY => Yes
Protocols => dict, file, ftp, ftps, gopher, gophers, http, https, imap, imaps, ldap, ldaps, mqtt, pop3, pop3s, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp
HTTP input encoding translation => disabled
mbstring.http_input => no value => no value
mbstring.http_output => no value => no value
mbstring.http_output_conv_mimetypes => ^(text/|application/xhtml\+xml) => ^(text/|application/xhtml\+xml)
session.cookie_httponly => no value => no value
https_proxy => http://proxy.myIntranet:8080
http_proxy => http://proxy.myIntranet:8080
$_SERVER['https_proxy'] => http://proxy.myIntranet:8080
$_SERVER['http_proxy'] => http://proxy.myIntranet:8080
((grep -i "url"))
/etc/php.d/20-curl.ini,
allow_url_fopen => On => On
allow_url_include => Off => Off
curl
cURL support => enabled
cURL Information => 7.76.1
curl.cainfo => no value => no value
url_rewriter.hosts => no value => no value
url_rewriter.tags => form= => form=
Подробнее здесь: [url]https://stackoverflow.com/questions/79769978/php-cli-running-with-curl-init-but-not-with-file-get-contents-how-to-enable[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия