<?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: How To Run A PHP Script In The Background</title>
	<atom:link href="http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/feed/" rel="self" type="application/rss+xml" />
	<link>http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/</link>
	<description>Slightly Advanced Computer Stuff (and some magic)</description>
	<lastBuildDate>Mon, 15 Mar 2010 20:08:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: ShavedApe</title>
		<link>http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/comment-page-2/#comment-33840</link>
		<dc:creator>ShavedApe</dc:creator>
		<pubDate>Sun, 28 Feb 2010 16:12:40 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/#comment-33840</guid>
		<description>Just wanted to say a big thank you been looking to do this for so long but couldnt find a way other than exec() and I could never get that to work the way I wanted the backgroundPost() has helped me massively so thank you :D</description>
		<content:encoded><![CDATA[<p>Just wanted to say a big thank you been looking to do this for so long but couldnt find a way other than exec() and I could never get that to work the way I wanted the backgroundPost() has helped me massively so thank you <img src='http://w-shadow.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hamad</title>
		<link>http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/comment-page-2/#comment-33399</link>
		<dc:creator>Hamad</dc:creator>
		<pubDate>Fri, 22 Jan 2010 03:31:34 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/#comment-33399</guid>
		<description>Thank you man I&#039;ve been looking for this for ages

I&#039;m working on a web crawler script that takes a long time to finish, which causes the connection to timeout.
Thanks to you I can do it now without the user thinking the website has faild.

I still can get the progress of the process by using a shared sessions variable and ajax to pull the current progress results.</description>
		<content:encoded><![CDATA[<p>Thank you man I&#8217;ve been looking for this for ages</p>
<p>I&#8217;m working on a web crawler script that takes a long time to finish, which causes the connection to timeout.<br />
Thanks to you I can do it now without the user thinking the website has faild.</p>
<p>I still can get the progress of the process by using a shared sessions variable and ajax to pull the current progress results.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: White Shadow</title>
		<link>http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/comment-page-2/#comment-31390</link>
		<dc:creator>White Shadow</dc:creator>
		<pubDate>Mon, 07 Sep 2009 11:29:04 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/#comment-31390</guid>
		<description>It &lt;em&gt;already&lt;/em&gt; passes any parameters via POST, though it may not be immediately obvious. What it does is take the query string (e.g. &quot;file=some_file.dat&quot; in the example) and sends it as the body of the POST request. This means the requested file will see it as $_POST[&#039;file&#039;]. 

This may not be an optimal solution, but it should be pretty easy to change if you need to - change the function to take another arguments (e.g. $params, an array) and replace line 16 with something like
&lt;pre lang=&#039;php&#039;&gt;$out .= http_build_query($params);&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>It <em>already</em> passes any parameters via POST, though it may not be immediately obvious. What it does is take the query string (e.g. &#8220;file=some_file.dat&#8221; in the example) and sends it as the body of the POST request. This means the requested file will see it as $_POST['file']. </p>
<p>This may not be an optimal solution, but it should be pretty easy to change if you need to &#8211; change the function to take another arguments (e.g. $params, an array) and replace line 16 with something like</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$out</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">http_build_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: xendex</title>
		<link>http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/comment-page-2/#comment-31387</link>
		<dc:creator>xendex</dc:creator>
		<pubDate>Mon, 07 Sep 2009 07:13:26 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/#comment-31387</guid>
		<description>Thanks for the exelent solution, White Shadow.
I have a question about 2nd solution: how can I pass additional arguments via $_POST method(not GET like http://example.com/slow.php?file=some_file.dat) to the requested php-file? Need some example, please.</description>
		<content:encoded><![CDATA[<p>Thanks for the exelent solution, White Shadow.<br />
I have a question about 2nd solution: how can I pass additional arguments via $_POST method(not GET like <a href="http://example.com/slow.php?file=some_file.dat)" rel="nofollow">http://example.com/slow.php?file=some_file.dat)</a> to the requested php-file? Need some example, please.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vibha</title>
		<link>http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/comment-page-2/#comment-30723</link>
		<dc:creator>vibha</dc:creator>
		<pubDate>Fri, 03 Jul 2009 05:17:01 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/#comment-30723</guid>
		<description>Thnx....it works !!!!!!!!!!!!</description>
		<content:encoded><![CDATA[<p>Thnx&#8230;.it works !!!!!!!!!!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ø How To Run A PHP Script In The Background &#124; W-Shadow.com ø</title>
		<link>http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/comment-page-1/#comment-30465</link>
		<dc:creator>ø How To Run A PHP Script In The Background &#124; W-Shadow.com ø</dc:creator>
		<pubDate>Sun, 07 Jun 2009 16:10:20 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/#comment-30465</guid>
		<description>[...] more here: ø How To Run A PHP Script In The Background &#124; W-Shadow.com ø   Share and [...]</description>
		<content:encoded><![CDATA[<p>[...] more here: ø How To Run A PHP Script In The Background | W-Shadow.com ø   Share and [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Um jeito fácil de realizar requisições assíncronas com PHP &#124; José Ricardo</title>
		<link>http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/comment-page-1/#comment-30356</link>
		<dc:creator>Um jeito fácil de realizar requisições assíncronas com PHP &#124; José Ricardo</dc:creator>
		<pubDate>Wed, 27 May 2009 20:41:46 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/#comment-30356</guid>
		<description>[...] [1] http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background [...]</description>
		<content:encoded><![CDATA[<p>[...] [1] <a href="http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background" rel="nofollow">http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: White Shadow</title>
		<link>http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/comment-page-1/#comment-16969</link>
		<dc:creator>White Shadow</dc:creator>
		<pubDate>Fri, 20 Feb 2009 15:25:06 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/#comment-16969</guid>
		<description>No problem :)</description>
		<content:encoded><![CDATA[<p>No problem <img src='http://w-shadow.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/comment-page-1/#comment-16962</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Fri, 20 Feb 2009 14:37:35 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/#comment-16962</guid>
		<description>Yes Arnie, that is worrying me as well, so I tried something novel and actually read the fsockopen documentation (http://us2.php.net/fsockopen).  The comment from &quot;joe at edwardsconsultants dot com 10-Aug-2003 09:56&quot; clued me into prepending the host with &quot;ssl://&quot; in the fsockopen call and now my code is happy (as am I).  So, for HTTPS, prepend the host and use port 443 (if you get stuck, use comment #12 debug as suggested):

function backgroundPost($url){
  $parts=parse_url($url);
 
  $fp = fsockopen(&#039;ssl://&#039;.$parts[&#039;host&#039;], 
          isset($parts[&#039;port&#039;])?$parts[&#039;port&#039;]:443, 
          $errno, $errstr, 30);
 
  if (!$fp) {
      return false;
  } else {
      $out = &quot;POST &quot;.$parts[&#039;path&#039;].&quot; HTTP/1.1\r\n&quot;;
      $out.= &quot;Host: &quot;.$parts[&#039;host&#039;].&quot;\r\n&quot;;
      $out.= &quot;Content-Type: application/x-www-form-urlencoded\r\n&quot;;
      $out.= &quot;Content-Length: &quot;.strlen($parts[&#039;query&#039;]).&quot;\r\n&quot;;
      $out.= &quot;Connection: Close\r\n\r\n&quot;;
      if (isset($parts[&#039;query&#039;])) $out.= $parts[&#039;query&#039;];
 
      fwrite($fp, $out);
      fclose($fp);
      return true;
  }
}

Thanks to Whiteshadow for a great idea and all of the follow up!</description>
		<content:encoded><![CDATA[<p>Yes Arnie, that is worrying me as well, so I tried something novel and actually read the fsockopen documentation (<a href="http://us2.php.net/fsockopen" rel="nofollow">http://us2.php.net/fsockopen</a>).  The comment from &#8220;joe at edwardsconsultants dot com 10-Aug-2003 09:56&#8243; clued me into prepending the host with &#8220;ssl://&#8221; in the fsockopen call and now my code is happy (as am I).  So, for HTTPS, prepend the host and use port 443 (if you get stuck, use comment #12 debug as suggested):</p>
<p>function backgroundPost($url){<br />
  $parts=parse_url($url);</p>
<p>  $fp = fsockopen(&#8217;ssl://&#8217;.$parts['host'],<br />
          isset($parts['port'])?$parts['port']:443,<br />
          $errno, $errstr, 30);</p>
<p>  if (!$fp) {<br />
      return false;<br />
  } else {<br />
      $out = &#8220;POST &#8220;.$parts['path'].&#8221; HTTP/1.1\r\n&#8221;;<br />
      $out.= &#8220;Host: &#8220;.$parts['host'].&#8221;\r\n&#8221;;<br />
      $out.= &#8220;Content-Type: application/x-www-form-urlencoded\r\n&#8221;;<br />
      $out.= &#8220;Content-Length: &#8220;.strlen($parts['query']).&#8221;\r\n&#8221;;<br />
      $out.= &#8220;Connection: Close\r\n\r\n&#8221;;<br />
      if (isset($parts['query'])) $out.= $parts['query'];</p>
<p>      fwrite($fp, $out);<br />
      fclose($fp);<br />
      return true;<br />
  }<br />
}</p>
<p>Thanks to Whiteshadow for a great idea and all of the follow up!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arnie Shore</title>
		<link>http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/comment-page-1/#comment-16955</link>
		<dc:creator>Arnie Shore</dc:creator>
		<pubDate>Fri, 20 Feb 2009 14:17:15 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/#comment-16955</guid>
		<description>There&#039;s a potential skunk at the ajax picnic that I, for one, occasionally forget - it&#039;s the two-channels limit thing.  (If some of you have tried to test-drive this issue, pls let us know - I haven&#039;t taken the time.)

When it rears its ugly head it&#039;s simply a hang - or unexpected delay - which can be really difficult to trace.  It bears thinking about while building an application.

I&#039;d asked on the GMaps API group re how Google seems to solve that, and the answer I got was that the limit is per-server; you may have noticed that Google employs several server addr&#039;s (MT1, MT2, etc.) to help solve it.  Which makes sense but which not all of us can do.</description>
		<content:encoded><![CDATA[<p>There&#8217;s a potential skunk at the ajax picnic that I, for one, occasionally forget &#8211; it&#8217;s the two-channels limit thing.  (If some of you have tried to test-drive this issue, pls let us know &#8211; I haven&#8217;t taken the time.)</p>
<p>When it rears its ugly head it&#8217;s simply a hang &#8211; or unexpected delay &#8211; which can be really difficult to trace.  It bears thinking about while building an application.</p>
<p>I&#8217;d asked on the GMaps API group re how Google seems to solve that, and the answer I got was that the limit is per-server; you may have noticed that Google employs several server addr&#8217;s (MT1, MT2, etc.) to help solve it.  Which makes sense but which not all of us can do.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
