Run the PHP script as a background process on the Wamp server

I have two php scripts that need to be run as continuous processes in the background on the WAMP server.

The Wamp server is installed in a window of 7 PCs. These scripts are already in a separate folder in the www root directory.

Apache Version: 2.2.8
PHP Version: 5.2.6

Since this is not a unix platform, I cannot use the nohup PHP .php > /dev/null & to do this job. I am looking for a similar command or method that works on the Windows platform of a wamp server.

Can someone explain the steps I need to take to complete this task?

+4
source share
5 answers
  • create a batch file to run php script using php executable file "C: \ wamp \ php \ php.exe C: \ wamp \ www \ index.php"
  • add this batch file to the Scheduled task in the Windows Control Panel.
+10
source

Just use this feature. It runs on both operating systems (Windows and Linux):

 function execInBackground($cmd){ if (substr(php_uname(), 0, 7) == "Windows"){ pclose(popen("start /B ". $cmd, "r")); }else{ exec($cmd . " > /dev/null &"); } } 

Here is a simple example of using a function:

 execInBackground('php feed/handleFeed.php db_name '.$second_param); 

In the above example, we start the script handleFeed.php , which is located in a folder called "feed" , and we pass parameters 2 (the database name and another second parameter).

+8
source

Between this: http://php.net/manual/en/install.windows.commandline.php and using the "at" utility you should be able to work.

0
source

You can use "start" before starting the background script. Example:

create cron.cmd with

 start /B php.exe "path to your script 1" start /B php.exe "path to your script 2" 

You can show the person about the launch command:

  • Win - R
  • type cmd
  • type help start
0
source

This is what I did:

  • Php file

     <?php my code goes here ?> 

    * Please note that if you use the HTTP API / CURL in the CLI, use dl("php_curl.dll");

    this loads curl in cli

  • Now I have added PHP to the variable path to Windows, this can be done using my computer, properties, additional parameters, environment variables, new

  • Then I created a .bat file, just open notepad and enter the code below and save as myfile.bat

     @ECHO OFF php -fd:\wamp\www\V3\task.php 

    This site can help you with the syntax of the .bat file.

  • Now create a new scheduled task on Windows and call the above .bat file as a source,

0
source

All Articles