Jump to content

time out problem in curl


bhavin12300

Recommended Posts

hi

i am curl to fetch webpage from server.

i want to fetch two webpage one after another.

 

when i request one page from script,it is working perfectly.but when i insert code to fetch another page after first page it give me timeout error.

it  worked perfectly fine  if i request both page in individual script,but when i insert request code for file "two" after request code of file "one", it give me timeout error.

$web_page = http_get("http://travel.travelocity.com/flights/AirSearch.do?SEQ=1217741147969732008&breadcrumbStart=1", $referer="");
$web_page = http_get("http://travel.travelocity.com/flights/AirSearch.do?SEQ=1217741147969732008&breadcrumbStart=2", $referer="");

These are two pages.

Again,

if i insert one of any request in script alone it is working just fine but not working if i put both  together.

whats wrong in it???

Link to comment
https://forums.phpfreaks.com/topic/117913-time-out-problem-in-curl/
Share on other sites

sorry i forgot to mention that http_get is my function and its defination is as follow.

function http_get($target, $ref)
    {
    return http($target, $ref, $method="GET", $data_array="", EXCL_HEAD);
    }

function http($target, $ref, $method, $data_array, $incl_head)
{
    # Initialize PHP/CURL handle
$ch = curl_init();

    # Prcess data, if presented
    if(is_array($data_array))
        {
    # Convert data array into a query string (ie animal=dog&sport=baseball)
        foreach ($data_array as $key => $value) 
            {
            if(strlen(trim($value))>0)
                $temp_string[] = $key . "=" . urlencode($value);
            else
                $temp_string[] = $key;
            }
        $query_string = join('&', $temp_string);
        }
        
    # HEAD method configuration
    if($method == HEAD)
        {
    	curl_setopt($ch, CURLOPT_HEADER, TRUE);                // No http head
    curl_setopt($ch, CURLOPT_NOBODY, TRUE);                // Return body
        }
    else
        {
        # GET method configuration
        if($method == GET)
            {
            if(isset($query_string))
                $target = $target . "?" . $query_string;
            curl_setopt ($ch, CURLOPT_HTTPGET, TRUE); 
            curl_setopt ($ch, CURLOPT_POST, FALSE); 
            }
        # POST method configuration
        if($method == POST)
            {
            if(isset($query_string))
                curl_setopt ($ch, CURLOPT_POSTFIELDS, $query_string);
            curl_setopt ($ch, CURLOPT_POST, TRUE); 
            curl_setopt ($ch, CURLOPT_HTTPGET, FALSE); 
            }
    	curl_setopt($ch, CURLOPT_HEADER, $incl_head);   // Include head as needed
    curl_setopt($ch, CURLOPT_NOBODY, FALSE);        // Return body
        }
        
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE_FILE);   // Cookie management.
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIE_FILE);
curl_setopt($ch, CURLOPT_TIMEOUT, CURL_TIMEOUT);    // Timeout
curl_setopt($ch, CURLOPT_USERAGENT, WEBBOT_NAME);   // Webbot name
curl_setopt($ch, CURLOPT_URL, $target);             // Target site
curl_setopt($ch, CURLOPT_REFERER, $ref);            // Referer value
curl_setopt($ch, CURLOPT_VERBOSE, FALSE);           // Minimize logs
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);    // No certificate
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);     // Follow redirects
curl_setopt($ch, CURLOPT_MAXREDIRS, 4);             // Limit redirections to four
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);     // Return in string
    
    # Create return array
    $return_array['FILE']   = curl_exec($ch); 
    $return_array['STATUS'] = curl_getinfo($ch);
    $return_array['ERROR']  = curl_error($ch);
    
    # Close PHP/CURL handle
  	curl_close($ch);
    
    # Return results
  	return $return_array;
    }

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.