function - PHP-Nginx timeout error -
i have written php code finds title of webpage , writes title database.
till had no problems list got expanded , more websites means more required time php function. causes nginx web-server run "timeout" error.
i not want increase timeout setting nginx defaults since don't want abused other users on other pages sending long requests , keeping server busy.
here code i'm using getting title ;
function get_data($url) { $ch = curl_init(); $timeout = 15; curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_useragent,'mozilla/5.0 (windows; u; windows nt 5.1; en-us; rv:1.8.1.13) gecko/20080311 firefox/2.0.0.13'); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_timeout, 60); curl_setopt($ch, curlopt_httpget, 1); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_followlocation, true); curl_setopt($ch, curlopt_connecttimeout, $timeout); $data = curl_exec($ch); if(strlen($data)>0){ $data = trim(preg_replace('/\s+/', ' ', $data)); // supports line breaks inside <title> preg_match("/\<title\>(.*)\<\/title\>/i",$data,$title); // ignore case return $title[1]; }
the function works few websites. there anyway can make dynamic? "website 1 - done" "website 2 - done" "website 3 - done" , follows nginx doesn't show timeout error?
Comments
Post a Comment