Two methods are analyzed here:

the first method:

The content of a.php file is as follows:

 ini_set ("error_log", "c:\ php \ php_error.log");
 error_log ("a.php is execute ----------", 0);
 ignore_user_abort ();//No blocking operation in the background
 set_time_limit (0);//keep running for me
 $zhoz_execute_time=30;//Run time seconds, set here to run once a minute.
 do {
  //Anything i want to execute can be written here
  error_log ("a is do !!!! ----------", 0);
  sleep ($zhoz_execute_time);//run at the specified track time
 } while (true);

But there is a disadvantage here,You need to run this php file first, such as by url:http://www.zhoz.com/zhoz.php

It only needs to be executed once here,Then close the page.

In addition, when apache/iis is restarted, this script will not be executed.

To this end, I thought of another method:

Run under cmd:

php-win.exe -c "c:\ php \ php.ini" -f c:\ apache2.2 \ htdocs \ a.php

(You only need to run it once here,Running more time will shorten the operation.)

In this case,This script will still run even if I restart apache/iis.

There are also disadvantages:restart the machine or kill the process php-win.exe, of course it can't run ...

This solution,You can add a startup item to create a bat, which should be perfectly solved!

The second method:

b.php content:

  $fp=fopen ("c:\\ test \\ a.txt", "a +");
  fwrite ($fp, "test \ r \ n");
  fclose ($fp);

Then write a bat file with:

c:\ php \ php -c c:\ php \ php.ini -f c:\ apache2.2 \ htdocs \ b.php


Then use that at command to add it to the scheduled task

  • Previous SQL Server 2008 login with 'sa' failed, solution to enable 'sa' login
  • Next Detailed usage case of TelephonyManager class in Android