Re: [PHP] How to detect a PHP script time-out?
Tamas Arpad wrote: There was a discussion about this topic on the dev list, and because of many reasons the current functionality of register_shutdown_function() will remain the same in future releases too. Joseph Tate is working on a new function (apache_register_shutdown_function) to make it possible on apache to use the old behavior (Thanks Joseph! :)). Great! Love you guys! This "buggy" function is coming in quite handy :) Jc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to detect a PHP script time-out?
> Cool! I just tested it out and it works. At lest under PHP 4.3.0 and > Apache 1.3.26. > > But according to the bug report this functionality may change in the > future and a new function apache_register_shutdown() might replace the > current one ... > > The current functionality is *not* what is documented, but is it was is > *intended*. I.e. will the current functionality be change to be what the > docs say or will it continue and the docs will be changed? > > I will be using this functionality and need to know if it will change in > future releases ... There was a discussion about this topic on the dev list, and because of many reasons the current functionality of register_shutdown_function() will remain the same in future releases too. Joseph Tate is working on a new function (apache_register_shutdown_function) to make it possible on apache to use the old behavior (Thanks Joseph! :)). Arpi -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to detect a PHP script time-out?
Robert Fisher wrote: If you are willing to do a rewrite, then have your main script start a fork, or child process. According to Arpi (see below) I can use register_shutdown(), as the docs are wrong and it *will* send output to the browser *before* the connection is closed. Jc >Tamas Arpad wrote: > That's not right now. The manual is outdated. See this bug report > http://bugs.php.net/bug.php?id=15209. > This behavior was changed from 4.06 to 4.1. In newer versions of php the > registered functions will run before the connection is closed so ouptput can > be done from there as well. > So Jean you can make it as it is suggested on this page: > http://www.php.net/manual/en/features.connection-handling.php > > Arpi -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to detect a PHP script time-out?
Tamas Arpad wrote: That's not right now. The manual is outdated. See this bug report http://bugs.php.net/bug.php?id=15209. This behavior was changed from 4.06 to 4.1. In newer versions of php the registered functions will run before the connection is closed so ouptput can be done from there as well. > > So Jean you can make it as it is suggested on this page: > http://www.php.net/manual/en/features.connection-handling.php Cool! I just tested it out and it works. At lest under PHP 4.3.0 and Apache 1.3.26. But according to the bug report this functionality may change in the future and a new function apache_register_shutdown() might replace the current one ... The current functionality is *not* what is documented, but is it was is *intended*. I.e. will the current functionality be change to be what the docs say or will it continue and the docs will be changed? I will be using this functionality and need to know if it will change in future releases ... Thanks for this info. It was a great help! Jc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to detect a PHP script time-out?
On Wednesday 08 January 2003 06:42, Jean-Christian Imbeault wrote: > Timothy Hitchens ) wrote: > > Issue... as I said before the register shutdown won't work because: > > > > - output from the shutdown is not visible nor do you have access to some > > variables > > You are right. From the manual: > > http://www.php.net/manual/en/function.register-shutdown-function.php > > " The registered shutdown functions are called after the request has > been completed (including sending any output buffers), so it is not > possible to send output to the browser using echo() or print(), or > retrieve the contents of any output buffers using ob_get_contents()." That's not right now. The manual is outdated. See this bug report http://bugs.php.net/bug.php?id=15209. This behavior was changed from 4.06 to 4.1. In newer versions of php the registered functions will run before the connection is closed so ouptput can be done from there as well. So Jean you can make it as it is suggested on this page: http://www.php.net/manual/en/features.connection-handling.php Arpi -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to detect a PHP script time-out?
If you are willing to do a rewrite, then have your main script start a fork, or child process. The child process would run your script while the parent would do nothing else but wait for the child. if the child times out the parent will know and you can then print out a error message. See the following on how to implement forks (process controls). It is kind of confusing and could be fatal to your system load if done incorrectly. http://www.php.net/manual/en/ref.pcntl.php __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to detect a PHP script time-out?
Timothy Hitchens ) wrote: No you can't.. the issue with this is that you need to have error reporting turned on.. so you will need to have more error collecting or removing. [..] This isn't the best for a production env but this is the best I can see considering you don't want to rewrite!! Ouch. Having error reproting on is definitely not a good thing. But the again it can be set on a page by page basis so I could turn it off in the php.ini file, and turn it on only in those pages where I need to check for a time out. And it's not that I won't do a re-write it's just that I was hoping for something easy to implement. If a re-write is the only answer then I'll do it of course. I also posted a feature request asking for a shutdown() type function that can be used to send output back to the browser in the case of a timeout. Hope they'll implement it ;) Jc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How to detect a PHP script time-out?
No you can't.. the issue with this is that you need to have error reporting turned on.. so you will need to have more error collecting or removing. The error is something like: "Fatal error: Maximum execution.." so we are checking for just this in the regex. This isn't the best for a production env but this is the best I can see considering you don't want to rewrite!! Timothy Hitchens (HiTCHO) Open Platform Consulting e-mail: [EMAIL PROTECTED] > -Original Message- > From: Jean-Christian Imbeault [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, 8 January 2003 5:17 PM > To: [EMAIL PROTECTED] > Subject: Re: [PHP] How to detect a PHP script time-out? > > > Timothy Hitchens ) wrote: > > There is one last option ... register an output buffer as I > suggested > > before suggested but this time do the reverse and you don't have to > > rewrite your scripts: > > Ok I think I understand what you are proposing. I just have > one question > about your example code. > > Where does the string "Maximum execution" come from? Is this output > automatically by PHP when a script times out? > > Would it be possible to use: > > if (connection_status == 2) {} > > Jc > > > > > > ob_start('scriptTimeout'); > > > > // set to 1 this should show the error below set to 2 and above you > > should get the normal output!! set_time_limit(1); > > > > function scriptTimeout($buffer) > > { > > if (eregi('Maximum execution', $buffer)) > > { > > $buffer = 'Server Overloaded!!'; > > } > > > > return $buffer; > > } > > > > // > > // content area > > // > > > > for ($i = 0; $i < 100; $i++) > > { > > $output = $i; > > } > > > > echo 'We are upto a final count of: '.$output; > > > > ?> > > > > > -- > 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] How to detect a PHP script time-out?
Timothy Hitchens ) wrote: There is one last option ... register an output buffer as I suggested before suggested but this time do the reverse and you don't have to rewrite your scripts: Ok I think I understand what you are proposing. I just have one question about your example code. Where does the string "Maximum execution" come from? Is this output automatically by PHP when a script times out? Would it be possible to use: if (connection_status == 2) {} Jc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How to detect a PHP script time-out?
There is one last option ... register an output buffer as I suggested before suggested but this time do the reverse and you don't have to rewrite your scripts: Please be aware that this will add _some_ load but will solve your issues. You can then add in things like error checking etc etc Timothy Hitchens (HiTCHO) Open Platform Consulting e-mail: [EMAIL PROTECTED] > -Original Message- > From: Jean-Christian Imbeault [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, 8 January 2003 3:43 PM > To: [EMAIL PROTECTED] > Subject: Re: [PHP] How to detect a PHP script time-out? > > > Timothy Hitchens ) wrote: > > Issue... as I said before the register shutdown won't work because: > > > > - output from the shutdown is not visible nor do you have access to > > some variables > > You are right. From the manual: > http://www.php.net/manual/en/function.register-shutdown-function.php " The registered shutdown functions are called after the request has been completed (including sending any output buffers), so it is not possible to send output to the browser using echo() or print(), or retrieve the contents of any output buffers using ob_get_contents()." That's no good ... There definitely should be a function that gets called (or can be registered) when a script times out ... A time-out indicates an error on my end (the server) and I would like to be able to detect it and take action ... If the is no way to do this then PHP is lacking. I'd definitely ask for this to be implemented ;) Jc -- 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] How to detect a PHP script time-out?
Timothy Hitchens ) wrote: Issue... as I said before the register shutdown won't work because: - output from the shutdown is not visible nor do you have access to some variables You are right. From the manual: http://www.php.net/manual/en/function.register-shutdown-function.php " The registered shutdown functions are called after the request has been completed (including sending any output buffers), so it is not possible to send output to the browser using echo() or print(), or retrieve the contents of any output buffers using ob_get_contents()." That's no good ... There definitely should be a function that gets called (or can be registered) when a script times out ... A time-out indicates an error on my end (the server) and I would like to be able to detect it and take action ... If the is no way to do this then PHP is lacking. I'd definitely ask for this to be implemented ;) Jc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to detect a PHP script time-out?
You can try that code. It looks like connection_timeout() is deprecated, however. You should probably use connection_aborted() and connection_status() http://www.php.net/manual/en/function.connection-status.php http://www.php.net/manual/en/function.connection-aborted.php Read the user notes in connection_aborted, there appear to be issues to take into account. Take care, Greg -- phpDocumentor http://www.phpdoc.org "Jean-Christian Imbeault" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Greg Beaver wrote: > > > > http://www.php.net/manual/en/features.connection-handling.php > > Nice! > > So if I understand correctly I need to: > > 1- register a shutdown function > 2- have this function check if it was called b/c of a conection_timeout() > 3- And if so have the function print out my timeout error message > > So in my script I could put something like this: > > function timeout_message() { >if ( connection_timeout() ) { > echo "server busy, try again later"; >} > } > > register_shutdown_function('timeout_message'); > > [rest of my script goes here ...] > > ?> > > If the script timesout then my error function is called. Is that about > right? > > Jc > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How to detect a PHP script time-out?
Issue... as I said before the register shutdown won't work because: - output from the shutdown is not visible nor do you have access to some variables Result: no message as you wanted to show to the client. Timothy Hitchens (HiTCHO) Open Platform Consulting e-mail: [EMAIL PROTECTED] > -Original Message- > From: Jean-Christian Imbeault [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, 8 January 2003 3:29 PM > To: [EMAIL PROTECTED] > Subject: Re: [PHP] How to detect a PHP script time-out? > > > Greg Beaver wrote: > > > > http://www.php.net/manual/en/features.connection-handling.php > > Nice! > > So if I understand correctly I need to: > > 1- register a shutdown function > 2- have this function check if it was called b/c of a > conection_timeout() > 3- And if so have the function print out my timeout error message > > So in my script I could put something like this: > > function timeout_message() { >if ( connection_timeout() ) { > echo "server busy, try again later"; >} > } > > register_shutdown_function('timeout_message'); > > [rest of my script goes here ...] > > ?> > > If the script timesout then my error function is called. Is > that about > right? > > Jc > > > -- > 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] How to detect a PHP script time-out?
Greg Beaver wrote: http://www.php.net/manual/en/features.connection-handling.php Nice! So if I understand correctly I need to: 1- register a shutdown function 2- have this function check if it was called b/c of a conection_timeout() 3- And if so have the function print out my timeout error message So in my script I could put something like this: function timeout_message() { if ( connection_timeout() ) { echo "server busy, try again later"; } } register_shutdown_function('timeout_message'); [rest of my script goes here ...] ?> If the script timesout then my error function is called. Is that about right? Jc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to detect a PHP script time-out?
Hi Jean-Christian, see: http://www.php.net/manual/en/features.connection-handling.php Take care, Greg -- phpDocumentor http://www.phpdoc.org "Jean-Christian Imbeault" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Timothy Hitchens ) wrote: > > > > Set up output buffering on your page then if the page times out the > > buffer > > should be sent to the browser and that is loaded with your message. > > Ok. Is there another solution? > > The reason I ask is that in order to use your solution I would need to > redesign my pages (quite a few of them). > > I was hoping to be able to do something like this: > > if (timeout()) include("try_again.html"); > > Thanks, > > Jc > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How to detect a PHP script time-out?
You want a call back method for timeout none avail. - auto append won't work - register shutdown won't work I don't know of another solution right now. Timothy Hitchens (HiTCHO) Open Platform Consulting e-mail: [EMAIL PROTECTED] > -Original Message- > From: Jean-Christian Imbeault [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, 8 January 2003 1:43 PM > To: [EMAIL PROTECTED] > Subject: Re: [PHP] How to detect a PHP script time-out? > > > Timothy Hitchens ) wrote: > > > > Set up output buffering on your page then if the page times out the > > buffer should be sent to the browser and that is loaded with your > > message. > > Ok. Is there another solution? > > The reason I ask is that in order to use your solution I > would need to > redesign my pages (quite a few of them). > > I was hoping to be able to do something like this: > > if (timeout()) include("try_again.html"); > > Thanks, > > Jc > > > -- > 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] How to detect a PHP script time-out?
Timothy Hitchens ) wrote: Set up output buffering on your page then if the page times out the buffer should be sent to the browser and that is loaded with your message. Ok. Is there another solution? The reason I ask is that in order to use your solution I would need to redesign my pages (quite a few of them). I was hoping to be able to do something like this: if (timeout()) include("try_again.html"); Thanks, Jc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How to detect a PHP script time-out?
This is a fairly simple one if both the server and browser obey the specs: Set up output buffering on your page then if the page times out the buffer should be sent to the browser and that is loaded with your message. PSEUDO CODE: start output buffering put into buffer the required message start building actual page in a string behind the scenes fork--> page times out the buffer is sent out --> page ends properly ... clear the buffer and output the string you built Timothy Hitchens (HiTCHO) Open Platform Consulting e-mail: [EMAIL PROTECTED] > -Original Message- > From: Jean-Christian Imbeault [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, 8 January 2003 1:25 PM > To: [EMAIL PROTECTED] > Subject: [PHP] How to detect a PHP script time-out? > > > How can I detect if my PHP script is about to time-out? > > I would like to be able to detect a time-out and display a > page with an > appropriate error message "i.e. the server is busy now, > please try again > later". > > Jc > > > -- > 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] How to detect a PHP script time-out?
How can I detect if my PHP script is about to time-out? I would like to be able to detect a time-out and display a page with an appropriate error message "i.e. the server is busy now, please try again later". Jc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php