简体   繁体   中英

500 Server error file_get_contents

I have two project on same server. I want some data form on my website so I am using file_get_contents; most of the time I get the 500 internal error

I checked that my url fopen is on using phpinfo() .

With default settings, file_get_content() doesn't work behind a proxy or it cannot handle timeouts. It's normally recommended to read local files.

Therefore use cURL instead.

Below function could be used for the job:

function http_request($uri, $time_out = 10, $headers = 0)
{
    // Initializing
    $ch = curl_init();

    // Set URI
    curl_setopt($ch, CURLOPT_URL, trim($uri));

    curl_setopt($ch, CURLOPT_HEADER, $headers);

    // 1 - if output is not needed on the browser
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    // Time-out in seconds
    curl_setopt($ch, CURLOPT_TIMEOUT, $time_out);

    // Executing
    $result = curl_exec($ch);

    // Closing the channel
    curl_close($ch);

    return $result;
}

Let me know whether your're using Linux or Windows to give you cURL installation tips

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM