1

I am scraping data for many items via php curl, But for few items, the target website send "504 Gateway Time-out nginx" error, I have no problem with that, But the main problem is it halted the whole script, So script stops after this error and don't scrape next items,

I just wanna ignore(handle) that error, So that it doesn't halt the script.

This link can be helpful to understand the question https://serverfault.com/questions/882421/504-gateway-time-out-nginx-on-apache-server/882431

johnDoe
  • 63
  • 2
  • 8

1 Answers1

2

Try this code

$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);

/* Get the HTML or whatever is linked in $url. */
$response = curl_exec($handle);

$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
if($httpCode == 504) {
    /* Handle 504 here. */
} else {
    /* Process data */
}

curl_close($handle);
michal.jakubeczy
  • 8,221
  • 1
  • 59
  • 63
  • Awesome, I am gonna try this – johnDoe Nov 08 '17 at 13:30
  • Sure, i am trying to figure out how i can implement this on multi curl request,but i think it is the right solution for the asked question, thanks:) – johnDoe Nov 08 '17 at 13:53
  • 2
    i've tried something similar but it does not really catch the error i still get:

    504 Gateway Time-out

    The server didn't respond in time.
    – Jah Oct 09 '19 at 22:25