{"id":308,"date":"2007-10-03T07:50:15","date_gmt":"2007-10-03T04:50:15","guid":{"rendered":"http:\/\/blog.flashcolony.com\/?p=308"},"modified":"2007-10-03T07:50:15","modified_gmt":"2007-10-03T04:50:15","slug":"how-to-run-php-code-in-the-background","status":"publish","type":"post","link":"https:\/\/salehalsaffar.com\/blog\/how-to-run-php-code-in-the-background\/","title":{"rendered":"How To Run PHP Code In The Background"},"content":{"rendered":"<p>Ever wondered what to do when your PHP script takes long time to execute? Especially when users value time and won&#8217;t wait long to open a web page. There is a solution for that by running part of your PHP code in the background as <a href=\"http:\/\/www.sitecrafting.com\">SiteCrafting Blog<\/a> <a href=\"http:\/\/www.sitecrafting.com\/blog\/to-run-php-code-in\/\">posted<\/a>. It&#8217;s simple as <a href=\"http:\/\/www.sitecrafting.com\/blog\/to-run-php-code-in\/\">this article<\/a> shows the command needed to execute a PHP scripts in the background without interfering with the page loading. It only works in Linux servers.<\/p>\n<p><code><br \/>\n&lt;%<br \/>\n  $command = &quot;\/usr\/bin\/php4 -f \/var\/www\/myweb\/image_resize.php&quot;;<\/p>\n<p>exec( &quot;$command &gt; \/dev\/null &amp;&quot;, $arrOutput );<br \/>\n  %&gt;<br \/>\n<\/code><\/p>\n<p>That code will execute the image_resize.php in the background. The PHP file that uses this command will be loaded normally without waiting for exec() to be done.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ever wondered what to do when your PHP script takes long time to execute? Especially when users value time and won&#8217;t wait long to open a web page. There is a solution for that by running part of your PHP code in the background as SiteCrafting Blog posted. It&#8217;s simple as this article shows the [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[19],"tags":[],"_links":{"self":[{"href":"https:\/\/salehalsaffar.com\/blog\/wp-json\/wp\/v2\/posts\/308"}],"collection":[{"href":"https:\/\/salehalsaffar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salehalsaffar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/salehalsaffar.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/salehalsaffar.com\/blog\/wp-json\/wp\/v2\/comments?post=308"}],"version-history":[{"count":0,"href":"https:\/\/salehalsaffar.com\/blog\/wp-json\/wp\/v2\/posts\/308\/revisions"}],"wp:attachment":[{"href":"https:\/\/salehalsaffar.com\/blog\/wp-json\/wp\/v2\/media?parent=308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salehalsaffar.com\/blog\/wp-json\/wp\/v2\/categories?post=308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salehalsaffar.com\/blog\/wp-json\/wp\/v2\/tags?post=308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}