<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
> <channel><title>Comments on: Executing and checking background shell process from PHP</title> <atom:link href="https://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html/feed" rel="self" type="application/rss+xml" /><link>https://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html</link> <description>Tiny bits of bioinformatics, [web-]programming etc</description> <lastBuildDate>Mon, 01 Jan 2024 17:12:20 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>https://wordpress.org/?v=3.8.27</generator> <item><title>By: daianne</title><link>https://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html#comment-541378</link> <dc:creator><![CDATA[daianne]]></dc:creator> <pubDate>Wed, 20 Dec 2017 09:09:36 +0000</pubDate> <guid
isPermaLink="false">http://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html#comment-541378</guid> <description><![CDATA[@Bogdan,
Thank you very much for your response and advice. I already did that, but so far the only one that works for me is to write the message on a file. However, i don&#039;t know how should i detect the error on that file, because if i&#039;m going to search the word &#039;Error or &#039;Failed&#039;, it will take forever since my data testing is more than 30gb. And i can&#039;t get to work out the thing that you said to check the file size since the log also writes the process on the file created. So even if I check the file size, it wont help me because it will always be greater than zero.
as for the alternative that you mention I can&#039;t get the exit code. Or better yet I&#039;m not sure how to get it done.]]></description> <content:encoded><![CDATA[<p>@Bogdan,<br
/> Thank you very much for your response and advice. I already did that, but so far the only one that works for me is to write the message on a file. However, i don&#8217;t know how should i detect the error on that file, because if i&#8217;m going to search the word &#8216;Error or &#8216;Failed&#8217;, it will take forever since my data testing is more than 30gb. And i can&#8217;t get to work out the thing that you said to check the file size since the log also writes the process on the file created. So even if I check the file size, it wont help me because it will always be greater than zero.</p><p>as for the alternative that you mention I can&#8217;t get the exit code. Or better yet I&#8217;m not sure how to get it done.</p> ]]></content:encoded> </item> <item><title>By: Bogdan</title><link>https://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html#comment-541185</link> <dc:creator><![CDATA[Bogdan]]></dc:creator> <pubDate>Mon, 18 Dec 2017 20:25:53 +0000</pubDate> <guid
isPermaLink="false">http://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html#comment-541185</guid> <description><![CDATA[@Daianne,
one of the ways would be to redirect stdout and stderr to files, and then check those files for any messages about success or failure - or even check if stdout/stderr/output files are larger than zero bytes (because zero may indicate an early failure, if the process is not running anymore).
Alternatively/in addition, if you start a shell script wrapper around your target application, then you can collect (from the shell script) the exit code of your target application and write it to some file, and then check if exit code was 0 or not.]]></description> <content:encoded><![CDATA[<p>@Daianne,<br
/> one of the ways would be to redirect stdout and stderr to files, and then check those files for any messages about success or failure &#8211; or even check if stdout/stderr/output files are larger than zero bytes (because zero may indicate an early failure, if the process is not running anymore).</p><p>Alternatively/in addition, if you start a shell script wrapper around your target application, then you can collect (from the shell script) the exit code of your target application and write it to some file, and then check if exit code was 0 or not.</p> ]]></content:encoded> </item> <item><title>By: daianne</title><link>https://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html#comment-541119</link> <dc:creator><![CDATA[daianne]]></dc:creator> <pubDate>Mon, 18 Dec 2017 06:57:06 +0000</pubDate> <guid
isPermaLink="false">http://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html#comment-541119</guid> <description><![CDATA[Hi, using this how would i catch the error if the command i execute has failed?]]></description> <content:encoded><![CDATA[<p>Hi, using this how would i catch the error if the command i execute has failed?</p> ]]></content:encoded> </item> <item><title>By: Bogdan</title><link>https://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html#comment-494764</link> <dc:creator><![CDATA[Bogdan]]></dc:creator> <pubDate>Thu, 30 Mar 2017 20:19:57 +0000</pubDate> <guid
isPermaLink="false">http://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html#comment-494764</guid> <description><![CDATA[David,
I was only running processes which would sooner or later exit/terminate on their own - no daemon/background processes.
So I never had to kill a process from PHP.
If you are wrapping the final script into a bash script, then you could add some kind of process management to that bash script.
For example, you could get the PID of the background python script, `sleep` for some time, then kill it from the bash script, then terminate the script.
I would generally advise against any kind of background process management from PHP.
Do you really need it?
It would likely be better to have an independent server-side &quot;worker&quot; process, connected to a job queue (e.g. `beanstalkd`), and have your PHP/frontend simply add jobs to that queue.]]></description> <content:encoded><![CDATA[<p>David,</p><p>I was only running processes which would sooner or later exit/terminate on their own &#8211; no daemon/background processes.<br
/> So I never had to kill a process from PHP.</p><p>If you are wrapping the final script into a bash script, then you could add some kind of process management to that bash script.<br
/> For example, you could get the PID of the background python script, `sleep` for some time, then kill it from the bash script, then terminate the script.</p><p>I would generally advise against any kind of background process management from PHP.<br
/> Do you really need it?<br
/> It would likely be better to have an independent server-side &#8220;worker&#8221; process, connected to a job queue (e.g. `beanstalkd`), and have your PHP/frontend simply add jobs to that queue.</p> ]]></content:encoded> </item> <item><title>By: David Wilson</title><link>https://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html#comment-494591</link> <dc:creator><![CDATA[David Wilson]]></dc:creator> <pubDate>Wed, 29 Mar 2017 18:41:26 +0000</pubDate> <guid
isPermaLink="false">http://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html#comment-494591</guid> <description><![CDATA[How can you kill a process triggered from PHP (example: PHP runs BASH, and then BASH runs py script). I normally do &lt;code&gt;kill -TERM -PID&lt;/code&gt; so I kill the parent and all the children processes.
But it does not work when I use PHP to start everyting. I get: &lt;code&gt;bash: kill: (-3707) - No such process&lt;/code&gt;
However, &lt;code&gt;ps&lt;/code&gt; command tells me that the process is running.
Anyone knows what I am doing wrong? Hell really appreciated.
David]]></description> <content:encoded><![CDATA[<p>How can you kill a process triggered from PHP (example: PHP runs BASH, and then BASH runs py script). I normally do <code>kill -TERM -PID</code> so I kill the parent and all the children processes.</p><p>But it does not work when I use PHP to start everyting. I get: <code>bash: kill: (-3707) - No such process</code></p><p>However, <code>ps</code> command tells me that the process is running.</p><p>Anyone knows what I am doing wrong? Hell really appreciated.</p><p>David</p> ]]></content:encoded> </item> <item><title>By: Alex</title><link>https://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html#comment-273408</link> <dc:creator><![CDATA[Alex]]></dc:creator> <pubDate>Thu, 18 Sep 2014 07:49:57 +0000</pubDate> <guid
isPermaLink="false">http://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html#comment-273408</guid> <description><![CDATA[I am new to php, can anyone please write a piece of code for me to initialize &quot;$hmmfile $fastafile &amp; $outfile&quot; to execute command  $ps = run_in_background(&quot;hmmsearch $hmmfile $fastafile &gt; $outfile&quot;); as these are file handlers, not simple variables.
thanks]]></description> <content:encoded><![CDATA[<p>I am new to php, can anyone please write a piece of code for me to initialize &#8220;$hmmfile $fastafile &amp; $outfile&#8221; to execute command  $ps = run_in_background(&#8220;hmmsearch $hmmfile $fastafile &gt; $outfile&#8221;); as these are file handlers, not simple variables.</p><p>thanks</p> ]]></content:encoded> </item> <item><title>By: Bogdan</title><link>https://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html#comment-101627</link> <dc:creator><![CDATA[Bogdan]]></dc:creator> <pubDate>Wed, 24 Jun 2009 08:23:23 +0000</pubDate> <guid
isPermaLink="false">http://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html#comment-101627</guid> <description><![CDATA[Joe,
how would you do that, given the example application above? I see no way of getting exit status from a process which has finished.]]></description> <content:encoded><![CDATA[<p>Joe,</p><p>how would you do that, given the example application above? I see no way of getting exit status from a process which has finished.</p> ]]></content:encoded> </item> <item><title>By: Joe</title><link>https://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html#comment-101626</link> <dc:creator><![CDATA[Joe]]></dc:creator> <pubDate>Wed, 24 Jun 2009 07:55:53 +0000</pubDate> <guid
isPermaLink="false">http://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html#comment-101626</guid> <description><![CDATA[function is_process_running($PID)
{
exec(&quot;ps $PID&quot;, $ProcessState);
return(count($ProcessState)&gt;= 2);
}
IMO, it is more elegant to check for the exit code instead.]]></description> <content:encoded><![CDATA[<p>function is_process_running($PID)<br
/> {<br
/> exec(&#8220;ps $PID&#8221;, $ProcessState);<br
/> return(count($ProcessState)&gt;= 2);<br
/> }</p><p>IMO, it is more elegant to check for the exit code instead.</p> ]]></content:encoded> </item> </channel> </rss>