<?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: Apache PHP MySQL  and Runaway Scripts</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2008/05/20/apache-php-mysql-and-runaway-scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2008/05/20/apache-php-mysql-and-runaway-scripts/</link>
	<description>Everything about MySQL Performance</description>
	<lastBuildDate>Sat, 07 Nov 2009 18:35:44 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Leon</title>
		<link>http://www.mysqlperformanceblog.com/2008/05/20/apache-php-mysql-and-runaway-scripts/comment-page-1/#comment-543709</link>
		<dc:creator>Leon</dc:creator>
		<pubDate>Sun, 19 Apr 2009 14:52:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=402#comment-543709</guid>
		<description>mm. I was seeing similar sleep issues . We run some data processing every minute via cron. We want the script to stop once per minute so the new process can take over.
We did this at the start of the script:
//get start time
$s = microtime(true);

Then once per loop of our analysis script check the time:
$runningfor = round(microtime(true) - $s, 4);
//if its over 60 seconds terminate the script
if($runningfor&gt;60){
die();
}

Hope that helps someone</description>
		<content:encoded><![CDATA[<p>mm. I was seeing similar sleep issues . We run some data processing every minute via cron. We want the script to stop once per minute so the new process can take over.<br />
We did this at the start of the script:<br />
//get start time<br />
$s = microtime(true);</p>
<p>Then once per loop of our analysis script check the time:<br />
$runningfor = round(microtime(true) &#8211; $s, 4);<br />
//if its over 60 seconds terminate the script<br />
if($runningfor&gt;60){<br />
die();<br />
}</p>
<p>Hope that helps someone</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2008/05/20/apache-php-mysql-and-runaway-scripts/comment-page-1/#comment-339481</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Sun, 03 Aug 2008 17:04:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=402#comment-339481</guid>
		<description>VovaNux,

It depends on how you design your application. If you&#039;re using PHP Fast-CGI to serve requests PCNTL will be available :)  You also ca get it compiled in with Mod_PHP I think though it would be dangerous as you will can get alarm triggered while in Apache code etc.</description>
		<content:encoded><![CDATA[<p>VovaNux,</p>
<p>It depends on how you design your application. If you&#8217;re using PHP Fast-CGI to serve requests PCNTL will be available <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   You also ca get it compiled in with Mod_PHP I think though it would be dangerous as you will can get alarm triggered while in Apache code etc.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vovaNux</title>
		<link>http://www.mysqlperformanceblog.com/2008/05/20/apache-php-mysql-and-runaway-scripts/comment-page-1/#comment-339339</link>
		<dc:creator>vovaNux</dc:creator>
		<pubDate>Sun, 03 Aug 2008 06:48:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=402#comment-339339</guid>
		<description>pcntl functions are available from command line only (if you have Linux). That&#039;s why it is quite hard to use them as most of your scripts are not run from the command line</description>
		<content:encoded><![CDATA[<p>pcntl functions are available from command line only (if you have Linux). That&#8217;s why it is quite hard to use them as most of your scripts are not run from the command line</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PHP</title>
		<link>http://www.mysqlperformanceblog.com/2008/05/20/apache-php-mysql-and-runaway-scripts/comment-page-1/#comment-336668</link>
		<dc:creator>PHP</dc:creator>
		<pubDate>Tue, 29 Jul 2008 08:57:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=402#comment-336668</guid>
		<description>Very beneficial performance tunning tips has been provided. Thanks.</description>
		<content:encoded><![CDATA[<p>Very beneficial performance tunning tips has been provided. Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2008/05/20/apache-php-mysql-and-runaway-scripts/comment-page-1/#comment-304824</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Sun, 25 May 2008 00:37:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=402#comment-304824</guid>
		<description>Lauri,

I&#039;ve did the test with mysql_xxx functions for you.   There is no difference - MySQL calls are not counted towards execution time.  If it works differently in your case please provide example code and PHP version - I&#039;m really curious.</description>
		<content:encoded><![CDATA[<p>Lauri,</p>
<p>I&#8217;ve did the test with mysql_xxx functions for you.   There is no difference &#8211; MySQL calls are not counted towards execution time.  If it works differently in your case please provide example code and PHP version &#8211; I&#8217;m really curious.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lauri</title>
		<link>http://www.mysqlperformanceblog.com/2008/05/20/apache-php-mysql-and-runaway-scripts/comment-page-1/#comment-304778</link>
		<dc:creator>lauri</dc:creator>
		<pubDate>Sat, 24 May 2008 19:11:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=402#comment-304778</guid>
		<description>I&#039;m not sure that you can actually have a completely runaway MySQL query. Eventually the max_execution_time will be reached, as the execution of mysql_?, PDO etc are counted towards the max_execution_time, and the script is aborted. In you tests however, the sleep() function that you used to &#039;simulate&#039; a query is not counted towards max_execution_time. In fact, in the 2nd  example only the for() instructions count as execution time. So even this script will eventually abort, but as the for() instruction take svery little CPU time it seems to just go on forever. AS for runaway queries, the test surely show something, but exactly what?</description>
		<content:encoded><![CDATA[<p>I&#8217;m not sure that you can actually have a completely runaway MySQL query. Eventually the max_execution_time will be reached, as the execution of mysql_?, PDO etc are counted towards the max_execution_time, and the script is aborted. In you tests however, the sleep() function that you used to &#8217;simulate&#8217; a query is not counted towards max_execution_time. In fact, in the 2nd  example only the for() instructions count as execution time. So even this script will eventually abort, but as the for() instruction take svery little CPU time it seems to just go on forever. AS for runaway queries, the test surely show something, but exactly what?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2008/05/20/apache-php-mysql-and-runaway-scripts/comment-page-1/#comment-304620</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Sat, 24 May 2008 07:14:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=402#comment-304620</guid>
		<description>Thanks Rasmus, 

But what is about using this approach for PHP-FastCGI,  Which is exactly environment which I found it working ? 

When if we stick to apache what do you propose as alternative ?   To have some watchdog script checking  running scripts and killing apache processes if they were serving request for too long ? Not overly user friendly.  Though I guess you can make front server to detect and error and display nicer message.</description>
		<content:encoded><![CDATA[<p>Thanks Rasmus, </p>
<p>But what is about using this approach for PHP-FastCGI,  Which is exactly environment which I found it working ? </p>
<p>When if we stick to apache what do you propose as alternative ?   To have some watchdog script checking  running scripts and killing apache processes if they were serving request for too long ? Not overly user friendly.  Though I guess you can make front server to detect and error and display nicer message.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rasmus</title>
		<link>http://www.mysqlperformanceblog.com/2008/05/20/apache-php-mysql-and-runaway-scripts/comment-page-1/#comment-304534</link>
		<dc:creator>Rasmus</dc:creator>
		<pubDate>Sat, 24 May 2008 04:48:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=402#comment-304534</guid>
		<description>Using signals in userspace PHP is a really bad idea.  You have no idea how the web server code you are running inside might be affected which is why that note is in the documentation.  Apache1 will send a SIGALRM when the configured timeout expires, but signal handling in Apache2 is completely different, so when you start debugging signals and timeouts you need to be very explicit about which environment you are in, and for Apache2, which mpm you are running.  In order to not clash with Apache&#039;s signal handling, PHP uses an itimer which triggers a SIGPROF (normally used for profiling).  A SIGPROF counts cpu time, so yes, if you do nothing but sleep or you are blocked on io from somewhere else, then you need to rely on the Apache SIGALRM to time you out.  But for any sort of busy loop, it will kick in.

The nasty thing is that 3rd party libraries can hijack any of these signals and it can be really hard to figure out who is doing that on you if you aren&#039;t getting the timeouts you are expecting.  There isn&#039;t much neither Apache nor PHP can do about that.</description>
		<content:encoded><![CDATA[<p>Using signals in userspace PHP is a really bad idea.  You have no idea how the web server code you are running inside might be affected which is why that note is in the documentation.  Apache1 will send a SIGALRM when the configured timeout expires, but signal handling in Apache2 is completely different, so when you start debugging signals and timeouts you need to be very explicit about which environment you are in, and for Apache2, which mpm you are running.  In order to not clash with Apache&#8217;s signal handling, PHP uses an itimer which triggers a SIGPROF (normally used for profiling).  A SIGPROF counts cpu time, so yes, if you do nothing but sleep or you are blocked on io from somewhere else, then you need to rely on the Apache SIGALRM to time you out.  But for any sort of busy loop, it will kick in.</p>
<p>The nasty thing is that 3rd party libraries can hijack any of these signals and it can be really hard to figure out who is doing that on you if you aren&#8217;t getting the timeouts you are expecting.  There isn&#8217;t much neither Apache nor PHP can do about that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peter</title>
		<link>http://www.mysqlperformanceblog.com/2008/05/20/apache-php-mysql-and-runaway-scripts/comment-page-1/#comment-303999</link>
		<dc:creator>peter</dc:creator>
		<pubDate>Fri, 23 May 2008 04:37:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=402#comment-303999</guid>
		<description>Absolutely.  If  PHP queries MySQL   Apache child will be busy and client stop will not abort the process.</description>
		<content:encoded><![CDATA[<p>Absolutely.  If  PHP queries MySQL   Apache child will be busy and client stop will not abort the process.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jeffatrackaid</title>
		<link>http://www.mysqlperformanceblog.com/2008/05/20/apache-php-mysql-and-runaway-scripts/comment-page-1/#comment-303875</link>
		<dc:creator>jeffatrackaid</dc:creator>
		<pubDate>Fri, 23 May 2008 01:07:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=402#comment-303875</guid>
		<description>I think the hanging behavior is what I see on a client&#039;s site.  On this site, they have some horrendous selects that dump to TMP tables.   There are a few selects that take nearly a minute to run.  I think the client abandons the page but the script or at least the select continues to run.  I will have to check more closely to see if we can replicate this and confirm the results.  On the database that runs the queries, the selects quickly pile up due to table locking.  The issue then snowballs as the web servers are quite busy during peak with 100&#039;s req/sec.  As the searches hang the apache slots, the site&#039;s performance degrades.</description>
		<content:encoded><![CDATA[<p>I think the hanging behavior is what I see on a client&#8217;s site.  On this site, they have some horrendous selects that dump to TMP tables.   There are a few selects that take nearly a minute to run.  I think the client abandons the page but the script or at least the select continues to run.  I will have to check more closely to see if we can replicate this and confirm the results.  On the database that runs the queries, the selects quickly pile up due to table locking.  The issue then snowballs as the web servers are quite busy during peak with 100&#8217;s req/sec.  As the searches hang the apache slots, the site&#8217;s performance degrades.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
