Re: Closing a connection to browser without exiting the script
| From: | David Négrier | Date: | Sun, 05 Nov 2006 12:04:42 +0000 |
| Subject: | Re: Closing a connection to browser without exiting the script | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-244228@lists.php.net to get a copy of this message | ||
Hi All,
Thanks a lot for your numerous answers.
I've learned a lot from all your suggestions.
Actually, combining all your answers, I'll come up with a solution.
To be more explicit on what I want to do, I want in fact to start a script, I want that script to
display a page, and then, I want that script not to stop, but I want to be able to access that script
back using AJAX calls from the web page. So my script is opening a network connection after having displayed the
web page and is waiting for incoming calls. Although no solution given here is fully satisfying (because I don't want
to launch antother script, I want to remain in the same) I still can find a way to close my connection to the browser (using
a header specifying the connection length) and then go back to my script using AJAX.
Thanks a lot for the time you took to propose solutions.
Best regards,
David.
www.thecodingmachine.com
Eric Butera a écrit :
On 11/1/06, David Négrier <d.negrier@thecodingmachine.com> wrote:Hello there, I'm having a somewhat unusual question here, and I cannot find any way to solve it. I have a PHP page that displays a message, and then, performs a very long operation. Note that it displays the message first. I do not intend to give some feedback to the user when the operation is done. I've seen I can use ignore_user_abort() to prevent the user from stopping the ongoing operation, but that solves only part of my problem. Because as long as the page is not fully loaded, the mouse cursor in the user's browser is showing a watch. So ideally, what I would like is to be able to close the connection from the server-side, but without using the exit() function, so my script keeps running afterwards. I know I could use a system() call to launch another process to do the processing, but I would like to avoid doing that, because there are many variables in the context that I cannot easily pass in parameter. I also tried to use the register_shutdown_function() to perform my operation after the page is displayed but since PHP 4.1.0, the connection is closed after the function is called.... Would any of you have an idea on how I could close that connection? Thanks a lot, David www.thecodingmachine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpIf you haven't gone with any of the listed methods yet you could use fsockopen with a timeout value to accomplish your goal. frontend.php: <?php $fp = fsockopen("localhost", 80); fwrite($fp, "GET /long_processing_script.php HTTP/1.0\r\n\r\n"); stream_set_timeout($fp, 1); echo "done!"; ?> long_processing_script.php: <?php ignore_user_abort(); set_time_limit(0); // do stuff here ?>