PHP5 giving failed to open stream: HTTP request failed error when using fopen

前端 未结 5 1249
渐次进展
渐次进展 2021-01-02 06:22

This problem seems to have been discussed in the past everywhere on google and here, but I have yet to find a solution.

A very simple fopen gives me a

相关标签:
5条回答
  • 2021-01-02 06:56

    Are you getting "HTTP request failed" without further details? The socket timeout could be expired. This default to 60 seconds. See: http://php.net/manual/en/function.socket-set-timeout.php

    0 讨论(0)
  • 2021-01-02 06:59

    Check your phpinfo output - is http present under Registered PHP Streams?

    0 讨论(0)
  • 2021-01-02 07:01

    I'm not at all sure about whether this is the problem or not, but I know in the past I've had problems with opening URLs with fopen, often due to php.ini's allow_url_fopen or other unknown security settings

    You may want to try cURL in PHP, which often works for me, you'll find an example really easily by googling that.

    0 讨论(0)
  • 2021-01-02 07:10

    Check that your php.ini config is set to allow fopen to open external URL's:

    allow_url_fopen "1"
    

    http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

    0 讨论(0)
  • 2021-01-02 07:12

    It sounds like your configuration isn't allowed to use file functions, which is common these days because of security concerns. If you have the cURL libraries available to you, I would recommend trying those out.

    PHP: cURL

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://www.google.ca/");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $file = curl_exec($ch);
    curl_close($ch);
    
    echo $file;
    
    0 讨论(0)
提交回复
热议问题