3

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.

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I've had the same results when I've set the timeout to -> 500 , 5000etc.. Do you think I need to change the setting within php.ini? Many thanks for your response.
Yes. Setting the timeout of the curl request doesn't help. You should set the time limit of the PHP script itself. I provided a link in the question. You can change php.ini or use the set_time_limit function.
You're awesome. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.