Current location: Hot Scripts Forums » Programming Languages » PHP » Execute PHP lines in the background


Execute PHP lines in the background

Reply
  #1 (permalink)  
Old 07-08-08, 07:24 PM
jumbo1 jumbo1 is offline
Wannabe Coder
 
Join Date: May 2006
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
Execute PHP lines in the background

Hi all

i have a form where my users submit some data. These data need processing, which may take quite some time. I don't want the user to wait that long, and worse, if he stops the page from loading in the browser, that may stop the processing and result in corrupt data.

I'd like to use a function or a way to keep running the processing lines on the server side, while the user is redirected to another page. It's probably something like a thread.

Is this possible?

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-08-08, 07:56 PM
Dissonance Dissonance is offline
Newbie Coder
 
Join Date: Jul 2008
Location: Kentucky, USA
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Running PHP scripts without having a user accessing a page is something that you shouldn't be doing for the most part.

However, in some cases, I can see it being necessary, but what you're asking is pretty unreasonable. The closest thing I can think of is creating a cron to run the php that processes data in the queue every x minutes/hours/days/weeks/etc.

It wouldn't be instantaneously ran, however.

Another method is to parse tiny bits of the data on every page load, providing you have enough traffic to initiate the parsing function frequently enough.

One last way to do it is to set a function to run after a set time on the next page load. I've seen a few PHP scheduling applications use this method.

However, none of those seem to do the background-processing that you're wanting.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-09-08, 01:37 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
To run a php file in the background regardless of what the user does:
PHP Code:

shell_exec('nohup /path/to/php -f/path/to/file.php >> /dev/null &'); 

To catch the output for logging purposes swap /dev/null to log location
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-09-08, 03:17 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 03:22 AM
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 11:17 AM
how to solve this PHP error? j14nhAo PHP 1 02-16-06 08:48 AM
Creating Dynamic Images With PHP cdphreaker PHP 0 02-20-05 04:26 PM


All times are GMT -5. The time now is 06:52 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.