fsockopen() Cookie problem Maximum execution time of 30 seconds exceeded

Im having a wierd problem with one of my php scripts opening a socket
connection with session variables. My page is continualy returning

Fatal error: Maximum execution time of 30 seconds exceeded in "bla bla
bla" line 43
line 43 is: $html .= fgets($fp, 4096); incase you need to know (i have
stripped alot of the comments out of the included code below)

I know im getting a result for: $Cookie = $_SERVER["HTTP_COOKIE"]
cause of the echo that is returned and does match the echo of the
session on all my other scripts. The thing is this code below works
for me if i remove the line:

$Headers .= "Cookie: ".$Cookie."\r\n";

problem is then i dont have my session data filling in the form
fields. As soon as I add this line so that the form fields can get the
information needed then i get this Maximum execution error.

I have tried using things like: stream_set_timeout($fp, 60); to
control this - but they dont seem to do anything. The script fails


/*
//==================================
//==============================
*/
session_start();

$URL = "vinyl-design"; // localhost network connection
$Cookie = $_SERVER["HTTP_COOKIE"]; // gives
"PHPSESSID=c32fc53d15e03ba25f1ad6be035a7eb1"

$Page = 'interface2/order_details.php';

$fp = fsockopen($URL, 80, $errno, $errstr, 30);

// check if the website is found
if(!$fp) {
echo 'Failed opening socket connection!<br>'.$errstr.'('.
$errno.')';
}
else {
// write to the http server
$Headers = "GET /".$Page." HTTP/1.1\r\n";
$Headers .= "Host: ".$URL."\r\n";
$Headers .= "Content-Type: text/html\r\n";
$Headers .= "Cookie: ".$Cookie."\r\n";
$Headers .= "Connection: Close\r\n\r\n";
fwrite($fp, $Headers);

// read the website
while(!feof($fp)) {
stream_set_timeout($fp, 60);

// store the html into a variable
$html .= fgets($fp, 4096);

$info = stream_get_meta_data($fp); // get any error information
while reading the data

if ($info['timed_out']) {
echo 'Connection timed out while trying to read data!';
}
}
fclose($fp);
}

echo $html;

/*
//==============================
//==================================
*/
Thorak [ Di, 20 März 2007 20:51 ] [ ID #1663214 ]

Re: fsockopen() Cookie problem Maximum execution time of 30 secondsexceeded

Thorak wrote:
> Im having a wierd problem with one of my php scripts opening a socket
> connection with session variables. My page is continualy returning
>
> Fatal error: Maximum execution time of 30 seconds exceeded in "bla bla
> bla" line 43
> line 43 is: $html .= fgets($fp, 4096); incase you need to know (i have
> stripped alot of the comments out of the included code below)

This means that reading the file takes longer than 30 sek and in the php.ini
it's set to that the script is only allowed to be executed in a timespan that
is at most 30 sek.

This has nothing to do with cookies nor sessions.


--

//Aho
Shion [ Di, 20 März 2007 21:01 ] [ ID #1663215 ]

Re: fsockopen() Cookie problem Maximum execution time of 30 seconds exceeded

On Mar 20, 1:01 pm, "J.O. Aho" <u... [at] example.net> wrote:
> Thorak wrote:
> > Im having a wierd problem with one of my php scripts opening a socket
> > connection with session variables. My page is continualy returning
>
> > Fatal error: Maximum execution time of 30 seconds exceeded in "bla bla
> > bla" line 43
> > line 43 is: $html .= fgets($fp, 4096); incase you need to know (i have
> > stripped alot of the comments out of the included code below)
>
> This means that reading the file takes longer than 30 sek and in the php.ini
> it's set to that the script is only allowed to be executed in a timespan that
> is at most 30 sek.
>
> This has nothing to do with cookies nor sessions.
>
> --
>
> //Aho

actually, as mentioned - if i remove the Cookie:
PHPSESSID=c32fc53d15e03ba25f1ad6be035a7eb1 from the headers sent in
the fsockopen there is no timeout error and the page loads fine - just
with no form fields filled in - Can you explain why this is then???

also - changed the timeout to be 60 seconds and then tried 120
seconds.... still came back with an error!
Thorak [ Di, 20 März 2007 21:53 ] [ ID #1663216 ]

Re: fsockopen() Cookie problem Maximum execution time of 30 seconds exceeded

OK... been workin on this for a couple days now - driving me nuts...
but I did manage to sort out one thing in all this time.

I can use session data from another user (we have multiple people
using the same system at our shop - therefore the data structure
itself is the same, just different values). Anyways... The script
listed above gives the timeout warning only if the user has another
page on the site open that is using the same session. If i hard code
in a different session number in the header 'Cookie:' area that
exists in PHP's session dir then it works fine - information fills
into the forms, no timeout errors etc.

To check this I started an new session on my machine and tried to run
my script -> Timeout error.
So i went to the PHP Session dir and found the
'sess_c32fc53d15e03ba25f1ad6be035a7eb1' file and copied it to a new
one with the name of 'sess_c32fc53d15e03ba25f1ad6be035a7eb2' (just
changed the last digit).

I hard coded this new number into the Cookie: header line again and
voila - all works fine. Change the hard coded Cookie: to the original
number and it times out.

Any ideas???
Thorak [ Mi, 21 März 2007 21:23 ] [ ID #1664369 ]

Re: fsockopen() Cookie problem Maximum execution time of 30 secondsexceeded

Thorak wrote:
> OK... been workin on this for a couple days now - driving me nuts...
> but I did manage to sort out one thing in all this time.
>
> I can use session data from another user (we have multiple people
> using the same system at our shop - therefore the data structure
> itself is the same, just different values). Anyways... The script
> listed above gives the timeout warning only if the user has another
> page on the site open that is using the same session. If i hard code
> in a different session number in the header 'Cookie:' area that
> exists in PHP's session dir then it works fine - information fills
> into the forms, no timeout errors etc.

Do you really need to send the session cookie?

By the way, I think the session cookie looks like this:
$Headers .= 'Cookie: '.ini_get('session.name').'='.session_id()."\r\n";

ini_get('session.name') -> session cookie name
session_id() -> session id (the string you playing with)


--

//Aho
Shion [ Mi, 21 März 2007 21:59 ] [ ID #1664370 ]
PHP » alt.php » fsockopen() Cookie problem Maximum execution time of 30 seconds exceeded

Vorheriges Thema: continental state function
Nächstes Thema: what does this code block do?