IT Community - Software Programming, Web Development and Technical Support

Info on background process in PHP

This is a discussion on Info on background process in PHP within the PHP Programming forums, part of the Web Development category; Hi, Running a background process in PHP In an ideal world, all of the functions that you need would be ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 08-07-2007, 03:08 AM
sivaramakrishnan sivaramakrishnan is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 74
sivaramakrishnan is on a distinguished road
Post Info on background process in PHP

Hi,

Running a background process in PHP

In an ideal world, all of the functions that you need would be available in the language of your choice. This is rarely the case for bioinformatics projects, where it’s often convenient or necessary to run a script or program outside your main script, grab the results and parse them. Easy enough - but if you’re writing a web application and the external program takes longer than a few seconds to run, you’re faced with a blank web page and confused users. Normally, the page loads only after all associated processes are complete.

So you’d like to run your external program in the background and display a reassuring message that says “Analysing sequence. . .”, or something similar. Here’s how you do that in PHP.

The PHP function that you need is shell_exec(). PHP has excellent online documentation: here’s the shell_exec() entry. A kind user has provided us with 2 functions for use under Linux: one for running a background process, another for monitoring a running process. I’ve edited them slightly and present them below:

function run_in_background($Command, $Priority = 0)
{
if($Priority)
$PID = shell_exec("nohup nice -n $Priority $Command 2> /dev/null & echo $!");
else
$PID = shell_exec("nohup $Command 2> /dev/null & echo $!");
return($PID);
}

function is_process_running($PID)
{
exec("ps $PID", $ProcessState);
return(count($ProcessState) >= 2);
}

Regards,
sivaraman.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-07-2007, 07:55 AM
Anand Anand is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 52
Anand is on a distinguished road
Default Re: Info on background process in PHP

Thanks for your info.
I have one question. Is there a way to find whether background process is enabled or not?.
__________________
None of us is As Strong as All of us.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-07-2007, 08:28 AM
sivaramakrishnan sivaramakrishnan is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 74
sivaramakrishnan is on a distinguished road
Thumbs up Re: Info on background process in PHP

Hi,

Just we know the php binary path(Ex:/home/php/bin/php), we can run the php background process.

Regards,
sivaraman.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-11-2007, 08:28 AM
venkat_charya venkat_charya is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 118
venkat_charya is on a distinguished road
Thumbs up Re: Info on background process in PHP

Is there any option to disable the background process?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-14-2007, 09:22 AM
vivekanandan vivekanandan is offline
D-Web Trainee
 
Join Date: Jul 2007
Posts: 41
vivekanandan is on a distinguished road
Default Re: Info on background process in PHP

Hi shiva,
The path /home/php/bin/php is the php installed path , it is not related with the enabling background process because it is inbuild with linux os, only we have to check shell_exec function is enabled or not , it is easily verified in the php
configuration file safe_mode_exec_dir directive

Regards,
Vivekanandan
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
To change the BackGround Color of Submenus without using CSS kingmaker HTML, CSS and Javascript Coding Techniques 1 01-20-2008 09:20 PM
Desktop Background Problem it.wily Operating Systems 13 01-10-2008 09:34 PM
Relation between process system time, process waiting time vigneshgets Operating Systems 0 08-01-2007 12:57 AM
Background Music in html Arun HTML, CSS and Javascript Coding Techniques 2 07-13-2007 01:49 AM
Background Check Search allenhan Advertising Sales and Affiliate Programs 0 06-28-2007 06:47 PM


All times are GMT -7. The time now is 05:55 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0