Running background process in php

Rakesh Sharma      2 Comments  

Running background process in php using wget and COM class

Running background process in php

A background process called any of program or code being execute in back end or that runs “behind the scenes”, without user intervention or like a cron job. Mostly used commands to run background process in php like wget on linux server and COM class on windows.
Let’s check how to execute or running background process in php. we need to send some php code to creating process in background and run using php commands.
In this article running background process in php we will explore some code for run background process on windows or linux.

creating a file which is sending some emails to check process successfully run or not

file_put_contents('email.php', '<?php 
mail("", "testbg", "background process has been started");
mail("", "testbg", "background process has been started");');

Running background process in php windows :-

For windows COM extension must be enabled on your server else you will get an error about COM missing.

Running "email.php" in background using $WshShell->Run on windows.

$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run("D:/xampp/php/php-cgi.exe -f D:/xampp/htdocs/new/email.php", 0, false);

Running background process in php linux :-

Running "email.php" in background using wget on linux.

$proc_command = "wget http://localhost/RAKESH/email.php -q -O - -b";
$proc = popen($proc_command, "r");

For more information about commands follow :-
wshshell, popen, wget

Now if your process has been gone in background you will get emails on given email id's. Now we are all set with running background process in php. So this way you can make a cron job using php without configure on server with a bit line of code. Just follow steps of code and done to run background process.

  • Et-et N Amparado

    how can i find the class com.. my script cannot find the class com.. thanks

    • rakesh sharma

      For this you need to enable COM support in php.ini. seems COM extension is not enabled on your server