0

HERE is my CURL CODE :

function get_curl_data($urlToHit) {
    $ch = curl_init($urlToHit);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_POST, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
    $result = curl_exec($ch);
    curl_close($ch);
}

I call the above function twice in same php page with 2 different URL on different HOST. When I do so, I get Service Unavailable -- With internal server error -- The error log has segmentation fault error.

But When I just make 1 Curl Call using any of the 2 URL , the code works fine.

Why isn't it allowing me to make 2 curl calls in same page ?

Any Help ?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Vivek
  • 11
  • 4

2 Answers2

0

I just add the curl option"FOLLOWLOCATION" and it works great for me, look below:

    function get_curl_data($urlToHit) {
        $ch = curl_init($urlToHit);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POST, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        $result = curl_exec($ch);
        curl_close($ch);
    }

    get_curl_data('http://google.com');
    get_curl_data('http://register.com');
    get_curl_data('http://stackoverflow.com');
  • Hi Nathan, Thanks for reply I tried the solution you gave, But that didn't work for me. I also tried `curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);` Still getting the same error. Is it that I make 2 curl calls on same page and there would some header conflict with 2 HTTP request on 2 diff HOST ? Any idea why does segmentation fault occurs giving internal server error ? – Vivek Dec 05 '14 at 05:42
0

The issue seems to have been resolved after I upgraded the PHP from PHP 5.3.3 to PHP 5.4.34 . PHP 5.3.3 has some bugs related to CURL : CURL ERROR: Recv failure: Connection reset by peer - PHP Curl

Community
  • 1
  • 1
Vivek
  • 11
  • 4