<?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>Sat, 21 Nov 2009 04:22:17 +0200</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<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>
	<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-16952</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Fri, 20 Feb 2009 14:10:44 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/#comment-16952</guid>
		<description>OK, I was curious, so I tried one more time with the debug you mentioned and got:

Bad Request
Your browser sent a request that this server could not understand.
Reason: You&#039;re speaking plain HTTP to an SSL-enabled server port.
Instead use the HTTPS scheme to access this URL, please.


Hint: https://dev.quote2bill.com/

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

I suspected it had something to do with that and had already changed the port number.  Any idea what else needs to be changed in the request?  Thanks.</description>
		<content:encoded><![CDATA[<p>OK, I was curious, so I tried one more time with the debug you mentioned and got:</p>
<p>Bad Request<br />
Your browser sent a request that this server could not understand.<br />
Reason: You&#8217;re speaking plain HTTP to an SSL-enabled server port.<br />
Instead use the HTTPS scheme to access this URL, please.</p>
<p>Hint: <a href="https://dev.quote2bill.com/" rel="nofollow">https://dev.quote2bill.com/</a></p>
<p>Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.</p>
<p>I suspected it had something to do with that and had already changed the port number.  Any idea what else needs to be changed in the request?  Thanks.</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-16950</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Fri, 20 Feb 2009 14:01:18 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/blog/2007/10/16/how-to-run-a-php-script-in-the-background/#comment-16950</guid>
		<description>I got the AJAX approach to work in about 5 minutes after struggling with exec(), system() etc for a couple of days, so I think I&#039;ll just cut my losses :)  I&#039;ll keep your idea about debugging in mind in case I run in to issues with AJAX.  Thanks!</description>
		<content:encoded><![CDATA[<p>I got the AJAX approach to work in about 5 minutes after struggling with exec(), system() etc for a couple of days, so I think I&#8217;ll just cut my losses <img src='http://w-shadow.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   I&#8217;ll keep your idea about debugging in mind in case I run in to issues with AJAX.  Thanks!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
