Setting Curl's Timeout in PHP

前端 未结 7 2101
你的背包
你的背包 2020-11-22 14:20

I\'m running a curl request on an eXist database through php. The dataset is very large, and as a result, the database consistently takes a long amount of time to return an

7条回答
  •  情深已故
    2020-11-22 14:39

    See documentation: http://www.php.net/manual/en/function.curl-setopt.php

    CURLOPT_CONNECTTIMEOUT - The number of seconds to wait while trying to connect. Use 0 to wait indefinitely.
    CURLOPT_TIMEOUT - The maximum number of seconds to allow cURL functions to execute.

    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 400); //timeout in seconds
    

    also don't forget to enlarge time execution of php script self:

    set_time_limit(0);// to infinity for example
    

提交回复
热议问题