Curl Timeout causing Firefox to Download PHP File ?!?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ave,

I¹m not sure what¹s causing the problem, but I have a feeling that its¹ a
timeout issue.
I have a curl function that retrieves specific data from a remote webpage.
The script works fine on my localhost, but when I upload it to my remote
server, the script tries to execute, but 10 ­ 15 seconds into it, Firefox
gives me an option to download the PHP script. Googling it I found that the
Curl function taking too long might cause a timeout, which Firefox
interprets by giving a Download option for the script. Safari on the other
hand says ³Could not load data from script². Again, same script works on
localhost on both browsers.

I don¹t know if that¹s the real cause or if something is wrong with my
script. Note that latest PHP & Curl are enabled and working on the remote
server, and other PHP pages & curl functions run on that remote server, so
that¹s not an issue.

Here¹s my curl function:

<?php
# Gather cookies in a Jar
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, ³path-to-cookieFileName");
curl_setopt($ch, CURLOPT_URL,"http://www.mywebsite.com";);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
ob_start();      // prevent any output
curl_exec ($ch); // execute the curl command
ob_end_clean();  // stop preventing output
curl_close ($ch);
unset($ch);

# Login with your Cookie Jar
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "usr=usrname&pwd=password");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, path-to-cookieFileName");
curl_setopt($ch, CURLOPT_URL,"http://www.mywebsite.com";);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec ($ch);
curl_close ($ch);

# Get the text in the middle of ...
function get_middle($source, $beginning, $ending, $init_pos) {
    $beginning_pos = strpos($source, $beginning, $init_pos);
    $middle_pos = $beginning_pos + strlen($beginning);
    $ending_pos = strpos($source, $ending, $beginning_pos + 1);
    $middle = substr($source, $middle_pos, $ending_pos - $middle_pos);
    return $middle;
}

# trim result and get what you need ...
$share_ratio = get_middle($result, 'Share ratio', '</tr>', 0);
$share_ratio2 = trim(ereg_replace("[\n\r\t]", "", $share_ratio));
$share_ratio3 = substr($share_ratio2, 25, 5);
echo "Ratio: <STRONG>$share_ratio3</STRONG>";
?>



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Rahul Sitaram Johari
CEO, Twenty Four Seventy Nine Inc.

W: http://www.rahulsjohari.com
E: sleepwalker@xxxxxxxxxxxxxxxx

³I morti non sono piu soli ... The dead are no longer lonely²


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux