Re: [PHP] spawing new PHP process
In article [EMAIL PROTECTED], Robert McPeak [EMAIL PROTECTED] wrote: I have other situations where I would like to somehow spawn a new php process so that the page loads quickly and my user doesn't get frustrated or confused. Hang on, there's lots of talking around the point here. This is not hard. Look in the manual under pcntl_fork. This will let you create a separate process that stays running all the time (not just when you're running a web page) and you can send commands to either using pcntl_signal (docs are out of date - also look up ticks) or through your database. You will need to have the CGI version of PHP installed, as well as mod_php - and in 4.3 this happens very easily. Having said all that, I've run into a separate probem further down the road doing just what you're wanting to do. My back-end process runs perfectly with no problems but after 5 mins or so starts generating chunk/page already free errors, then crashes. Looks to be a bug in there somewhere, but not sure where yet. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] spawing new PHP process
The correct solution for this particular problem is to just queue the outbound mail and have your MTA deliver them out of band. man sendmail -Rasmus On Tue, 26 Nov 2002, ROBERT MCPEAK wrote: I'm interested in spawing a new PHP process -- if that's the correct terminology. The situation is that I've got a very slow loading page, where, for example, I'm using PHP to send, say, 1000 emails. The user clicks submit, and, although PHP is firing out the emails, it appears to the user that page is hanging. I'd like to somehow send that process to the background and let the page load straight-away. In another scripting language I've used, this function was called spawn. Do we have something like this in PHP (I know we do!! Just can't find it.) I've looked through the docs but don't see what I'm looking for. Thanks in advance. -Bob -- 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] spawing new PHP process
Assuming you're working on UNIX--you need to use one of the execute functions (search for exec in the manual). You can spawn a separate PHP in the background in a number of way, for example, by using the screen program. If I remember correctly, you can't instantiate it directly and run it in the background because PHP does not close stdout and stderr--but this might have changed and/or I may be mistaken (nothing new there). Marco -- php|architect - The magazine for PHP Professionals The first monthly worldwide magazine dedicated to PHP programmers Come visit us at http://www.phparch.com! ---BeginMessage--- I'm interested in spawing a new PHP process -- if that's the correct terminology. The situation is that I've got a very slow loading page, where, for example, I'm using PHP to send, say, 1000 emails. The user clicks submit, and, although PHP is firing out the emails, it appears to the user that page is hanging. I'd like to somehow send that process to the background and let the page load straight-away. In another scripting language I've used, this function was called spawn. Do we have something like this in PHP (I know we do!! Just can't find it.) I've looked through the docs but don't see what I'm looking for. Thanks in advance. -Bob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ---End Message--- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] spawing new PHP process
Have your page before the email's would actually be sent, submit to a page with a frameset, in the bottom frame have a height of 1 pixel so that it's invisible. Then, in your PHP page, add something like: script language=javascript parent.topframe.progress.value = eval(parent.topframe.progress.value)+1; /script Have that print after every iteration of a mail being sent, and ofcourse you would have to create the necessary text boxes on your top frame and everything, but that would make it appear to be working to the user because the count of email's being sent would keep going up till it was done. On Tue, 2002-11-26 at 11:41, ROBERT MCPEAK wrote: I'm interested in spawing a new PHP process -- if that's the correct terminology. The situation is that I've got a very slow loading page, where, for example, I'm using PHP to send, say, 1000 emails. The user clicks submit, and, although PHP is firing out the emails, it appears to the user that page is hanging. I'd like to somehow send that process to the background and let the page load straight-away. In another scripting language I've used, this function was called spawn. Do we have something like this in PHP (I know we do!! Just can't find it.) I've looked through the docs but don't see what I'm looking for. Thanks in advance. -Bob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Adam Voigt ([EMAIL PROTECTED]) The Cryptocomm Group My GPG Key: http://64.238.252.49:8080/adam_at_cryptocomm.asc signature.asc Description: This is a digitally signed message part
Re: [PHP] spawing new PHP process
Rasmus, Thanks for you reply. I agree that what you suggest is the correct solution for the mail delivery scenario I used as an example. My example was poor in that in limited the scope of what I was asking. I have other situations where I would like to somehow spawn a new php process so that the page loads quickly and my user doesn't get frustrated or confused. Another such situation would be when I do time consuming operations on a MySql table, such as building an index or loading data. These operations may take several minutes and I'd like to avoid having to make my user wait for the page to load. What is the correct solution for this problem? I'm a newcomer to PHP, am quite excited by it, and really appreciate your insight. Thanks, Bob Rasmus Lerdorf [EMAIL PROTECTED] 11/26/02 11:46AM The correct solution for this particular problem is to just queue the outbound mail and have your MTA deliver them out of band. man sendmail -Rasmus On Tue, 26 Nov 2002, ROBERT MCPEAK wrote: I'm interested in spawing a new PHP process -- if that's the correct terminology. The situation is that I've got a very slow loading page, where, for example, I'm using PHP to send, say, 1000 emails. The user clicks submit, and, although PHP is firing out the emails, it appears to the user that page is hanging. I'd like to somehow send that process to the background and let the page load straight-away. In another scripting language I've used, this function was called spawn. Do we have something like this in PHP (I know we do!! Just can't find it.) I've looked through the docs but don't see what I'm looking for. Thanks in advance. -Bob -- 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 General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] spawing new PHP process
Usually the best solution is to use whatever backend you are talking to correctly. For a long-running MySQL query, for example, you should have a look at the non-blocking mysql_unbuffered_query() call. There is a fork() function in the pcntl extension and there is also a very experimental thread extension in PECL, but both of these should be a last resort. -Rasmus On Tue, 26 Nov 2002, ROBERT MCPEAK wrote: Rasmus, Thanks for you reply. I agree that what you suggest is the correct solution for the mail delivery scenario I used as an example. My example was poor in that in limited the scope of what I was asking. I have other situations where I would like to somehow spawn a new php process so that the page loads quickly and my user doesn't get frustrated or confused. Another such situation would be when I do time consuming operations on a MySql table, such as building an index or loading data. These operations may take several minutes and I'd like to avoid having to make my user wait for the page to load. What is the correct solution for this problem? I'm a newcomer to PHP, am quite excited by it, and really appreciate your insight. Thanks, Bob Rasmus Lerdorf [EMAIL PROTECTED] 11/26/02 11:46AM The correct solution for this particular problem is to just queue the outbound mail and have your MTA deliver them out of band. man sendmail -Rasmus On Tue, 26 Nov 2002, ROBERT MCPEAK wrote: I'm interested in spawing a new PHP process -- if that's the correct terminology. The situation is that I've got a very slow loading page, where, for example, I'm using PHP to send, say, 1000 emails. The user clicks submit, and, although PHP is firing out the emails, it appears to the user that page is hanging. I'd like to somehow send that process to the background and let the page load straight-away. In another scripting language I've used, this function was called spawn. Do we have something like this in PHP (I know we do!! Just can't find it.) I've looked through the docs but don't see what I'm looking for. Thanks in advance. -Bob -- 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 General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php