Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum execution time using cURL

Tags:

php

curl

I'm getting the error Fatal error: Maximum execution time of 30 seconds exceeded

which is odd because I have the timeout set to 0.

    function curl(){

        $this->options = Array(
        CURLOPT_RETURNTRANSFER => TRUE,   
        CURLOPT_FOLLOWLOCATION => FALSE, 
        CURLOPT_CONNECTTIMEOUT => 0, 
        CURLOPT_TIMEOUT => 0, 
        CURLOPT_MAXREDIRS => 20, 
        CURLOPT_USERAGENT => random_user_agent(), 
        CURLOPT_URL => $this->url, 
      );

       $this->ch = curl_init(); //Initalising curl;
     curl_setopt_array($this->ch, $this->options); 
     $this->data = curl_exec($this->ch); // Executing cURL;
     curl_close($this->ch);


     return $this->data;
     }  

Does anyone have an idea what the problem may be?

Many thanks in advance for any responses.

like image 899
Devstack Avatar asked Aug 31 '26 22:08

Devstack


1 Answers

Specifying 0 basically eliminates the timeout of the cUrl request.

However, the PHP script itself is not allowed to run for more than 30 seconds (by default). So if the request takes more than 30 seconds, the PHP script itself will be terminated, resulting in the message you get, regardless whether it was cUrl or just another piece of code that caused the script to take that long.

like image 176
GolezTrol Avatar answered Sep 04 '26 03:09

GolezTrol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!