PHP-CLI работает с curl_init, но не с file_get_contents, как включить?Php

Кемеровские программисты php общаются здесь
Anonymous
PHP-CLI работает с curl_init, но не с file_get_contents, как включить?

Сообщение 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);
< /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


Подробнее здесь: https://stackoverflow.com/questions/797 ... -to-enable

Вернуться в «Php»