Re: [PHP] Re: Register_Shutdown_Function ??
Windows? Blah. This stuff may very well not work there. No idea. -Rasmus On Sat, 18 May 2002, Jason Caldwell wrote: It doesn't matter. I'm setting the output *not* to the browser, but to the command shell, where I am running the script from. If you look at the errors, you'll see 2 of them, one points to line 7, where the IF() command is -- the script terminates there... I've put error_log() and exec() functions in place of the print() function -- it doesn't make a difference -- the script just won't execute the function in the register_shutdown_function() -- The following script works great (see below) -- it seems that for some reason its a TIMEOUT issue (bug). Running the script below, I will get the output of the print() function -- as stated, from the command line. I understand that it wouldn't show up in the browser. If I replace the exit; command with say a while(1); where the script will loop indefinitely, the timeout, set by the set_time_limit(1) will stop the script, but again -- register_shutdown_function() seems to want to work as the function IS CALLED, but NEVER executed, and instead errors on the 1st line in the FUNCTION -- always on a TIMEOUT. Run this script from your command line (ie. C:php test.php) -- then change the set_time_limit(30) to set_time_limit(1), and replace the exit with a while(1) -- run the script again, you'll see what I mean. And, if you still don't believe me, replace the print() in the function with error_log('Script Terminated', 3, 'errorlog.txt'); and see if the errorlog.txt file is ever created -- it isn't. ? set_time_limit(30); function clean_up() { print(Script Terminated); } register_shutdown_function(clean_up); exit; ? If anyone can offer any reason why its doing this, please help -- thanks. Jason Cc Zona [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Jason Caldwell) wrote: Here's my code: ? set_time_limit(1); function clean_up() { if(connection_status() TIMEOUT) print(Script timed out.\n); } register_shutdown_function(clean_up); while(1); ? Here's the message I get: (I should get Script timed out.) No, you shouldn't/wouldn't, because--as is noted in the docs http://php.net/register-shutdown-function--no more output (print is specifically mentioned as an example) can be sent to the browser at that stage. Try sending youself an email, or logging to a file instead. -- CC -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Register_Shutdown_Function ??
What makes you think you can echo something after your script has timed out? Change that print to write something to a file in /tmp and you will see that it works just fine. -Rasmus On Sat, 18 May 2002, Jason Caldwell wrote: Here's my code: ? set_time_limit(1); function clean_up() { if(connection_status() TIMEOUT) print(Script timed out.\n); } register_shutdown_function(clean_up); while(1); ? Here's the message I get: (I should get Script timed out.) --- br bFatal error/b: Maximum execution time of 1 second exceeded in bC:\test999.php/b on line b14/bbr br bFatal error/b: Maximum execution time of 1 second exceeded in bC:\test999.php/b on line b7/bbr -- Jason Caldwell [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I'm playing with the register_shutdown_function -- it's seems to work fine if I call exit() within my script -- however, it doesn't seem to work when the script times-out. Anyone know why? It's supposed to work in the event of an error, time-out, user-abort, or script-exit. Thanks Jason -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Register_Shutdown_Function ??
I just upgraded from 4.1.1 to 4.2.1 -- didn't fix the problem. I'd be curious to know if other Windows users are having the same problem. Thanks. Jason -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Register_Shutdown_Function ??
Here's my code: ? set_time_limit(1); function clean_up() { if(connection_status() TIMEOUT) print(Script timed out.\n); } register_shutdown_function(clean_up); while(1); ? Here's the message I get: (I should get Script timed out.) --- br bFatal error/b: Maximum execution time of 1 second exceeded in bC:\test999.php/b on line b14/bbr br bFatal error/b: Maximum execution time of 1 second exceeded in bC:\test999.php/b on line b7/bbr -- Jason Caldwell [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I'm playing with the register_shutdown_function -- it's seems to work fine if I call exit() within my script -- however, it doesn't seem to work when the script times-out. Anyone know why? It's supposed to work in the event of an error, time-out, user-abort, or script-exit. Thanks Jason -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Register_Shutdown_Function ??
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Jason Caldwell) wrote: Here's my code: ? set_time_limit(1); function clean_up() { if(connection_status() TIMEOUT) print(Script timed out.\n); } register_shutdown_function(clean_up); while(1); ? Here's the message I get: (I should get Script timed out.) No, you shouldn't/wouldn't, because--as is noted in the docs http://php.net/register-shutdown-function--no more output (print is specifically mentioned as an example) can be sent to the browser at that stage. Try sending youself an email, or logging to a file instead. -- CC -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Register_Shutdown_Function ??
It doesn't matter. I'm setting the output *not* to the browser, but to the command shell, where I am running the script from. If you look at the errors, you'll see 2 of them, one points to line 7, where the IF() command is -- the script terminates there... I've put error_log() and exec() functions in place of the print() function -- it doesn't make a difference -- the script just won't execute the function in the register_shutdown_function() -- The following script works great (see below) -- it seems that for some reason its a TIMEOUT issue (bug). Running the script below, I will get the output of the print() function -- as stated, from the command line. I understand that it wouldn't show up in the browser. If I replace the exit; command with say a while(1); where the script will loop indefinitely, the timeout, set by the set_time_limit(1) will stop the script, but again -- register_shutdown_function() seems to want to work as the function IS CALLED, but NEVER executed, and instead errors on the 1st line in the FUNCTION -- always on a TIMEOUT. Run this script from your command line (ie. C:php test.php) -- then change the set_time_limit(30) to set_time_limit(1), and replace the exit with a while(1) -- run the script again, you'll see what I mean. And, if you still don't believe me, replace the print() in the function with error_log('Script Terminated', 3, 'errorlog.txt'); and see if the errorlog.txt file is ever created -- it isn't. ? set_time_limit(30); function clean_up() { print(Script Terminated); } register_shutdown_function(clean_up); exit; ? If anyone can offer any reason why its doing this, please help -- thanks. Jason Cc Zona [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Jason Caldwell) wrote: Here's my code: ? set_time_limit(1); function clean_up() { if(connection_status() TIMEOUT) print(Script timed out.\n); } register_shutdown_function(clean_up); while(1); ? Here's the message I get: (I should get Script timed out.) No, you shouldn't/wouldn't, because--as is noted in the docs http://php.net/register-shutdown-function--no more output (print is specifically mentioned as an example) can be sent to the browser at that stage. Try sending youself an email, or logging to a file instead. -- CC -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: register_shutdown_function
afaik there is no way to call a class method with register_shutdown_function. simply use a function which calls your constructor function _shutdown() { xmysql::~xmysql(); } register_shutodown_function(_shutdown); Hayden Kirk [EMAIL PROTECTED] schrieb im Newsbeitrag 000501c1e40b$694cab50$62e7adcb@relic">news:000501c1e40b$694cab50$62e7adcb@relic... im trying to make a distructor for a mysql class to kill the connection when the object is destroyed using register_shutdown_function(~xmysql); if i put that in my class will it do that or am i getting confused. ~xmysql is a destructor function i made. Heres the code, will it work how i want it to? class xmysql { var $id; register_shutdown_function(~xmysql); function xmysql() { $id = mysql_connect(localhost,'mystic','cqr73chw'); or die(Could not connect to MYSQL database); } function ~xmysql() { mysql_close($id); } function GetID() { return $id; } } // end xmysql -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: register_shutdown_function and a MySQL query keeping connection with browser.
Even if you could get it to work, you'd be in trouble, as the PHP interpreter will clean up after you and trash your MySQL connection when it finishes, and anything that didn't get done before that would not work. You'll probably need to code this with two separate PHP files, one which calls the other using exec(/path/to/long.php , $results, $errorcode); Open the connection and do all the database stuff in long.php. -- WARNING [EMAIL PROTECTED] address is an endangered species -- Use [EMAIL PROTECTED] Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm - Original Message - From: Jeff Bearer [EMAIL PROTECTED] Newsgroups: php.general To: PHP-General [EMAIL PROTECTED] Sent: Wednesday, August 08, 2001 4:33 PM Subject: register_shutdown_function and a MySQL query keeping connection with browser. I've been working with register_shutdown_function() to have the browser kick of a long running script and move on to other tasks. I was having problems where the browser would sit and spin untill the function was done running, then would display the page. I tinkered with flush and fflush (i'm writing to a file also) but that didn't work either. Flush showed me the screen, but the browser still keeps the connection open untill the function was done running. It seems to be caused by the mysql query or result and the loop of the result set. Below is some of the test script I put together. I'm using the PEAR DB_mysql class. I'm using the sleep where the part of the real script takes some time to run. Has anyone dealt with this before, does anyone have any ideas? The only idea I've thougt of so far is to load the record set into a 2D array and then flush the result set. That might allow the browser to disconnect before the time comsuming job starts. Any suggestions will be appriciated. ?php include DB/mysql.php; $db=new DB_mysql; $db-connect($dsn); echo hello; register_shutdown_function(tester); exit; function tester(){ global $db; $sql=SELECT * FROM table; $result = $db-query($sql); while($row = $result-fetchRow(2)){ sleep(5); } } ? -- Jeff Bearer, RHCE Webmaster PittsburghLIVE.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]