Home > PHP > How To Run PHP Code In The Background

How To Run PHP Code In The Background

Ever wondered what to do when your PHP script takes long time to execute? Especially when users value time and won’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’s simple as this article shows the command needed to execute a PHP scripts in the background without interfering with the page loading. It only works in Linux servers.


<%
$command = "/usr/bin/php4 -f /var/www/myweb/image_resize.php";

exec( "$command > /dev/null &", $arrOutput );
%>

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.

Categories: PHP Tags:
  1. No comments yet.
  1. No trackbacks yet.

Get Adobe Flash player