This paper analyzes the automatic operation method of PHP file. Share to everyone for your reference, specific as follows:
Here are two ways to analyze:
The first method:
The contents of the a.php file are as follows:
<?php
ini_set ("Error_log", "C:\php\php_error.log");
Error_log ("a.php is execute----------", 0);
Ignore_user_abort (); Background without blocking operation
Set_time_limit (0);//Keep me running
$zhoz _execute_time = 30;//Run time seconds, set here to run once a minute.
do {
//What you want to do here can be written
error_log ("a" do!!!! ----------", 0);
Sleep ($zhoz _execute_time); Run at the specified orbital time
} while (true);
? >
But here is a disadvantage, you need to run this PHP file, such as through the URL to run: http://www.zhoz.com/zhoz.php
Just do it once and then close the page.
Also, when the Apache/iis is restarted, the script is not executed.
To this end, I thought of another way:
Run under cmd:
Php-win.exe-c "C:\php\php.ini"-F C:\Apache2.2\htdocs\a.php
(Just run it once, and running more time will shorten the operation.) )
That way, even if you restart Apache/iis, the script will still run.
Also has the shortcoming: restarts the machine or kills the process Php-win.exe, certainly it cannot run ...
This workaround can be added to the startup item as a bat should be perfectly resolved!
The second method:
b.php content:
<?php
$fp =fopen ("C:\\test\\a.txt", "A +");
Fwrite ($fp, "test \ r \ n");
Fclose ($FP);
? >
Then write a bat file in which to write:
C:\php\php-c c:\php\php.ini-f c:\Apache2.2\htdocs\b.php
Save
And then use that at command to add it to the scheduled task
More about PHP Interested readers can view the site topics: "PHP array" Operation tips Daquan, "PHP Sorting algorithm Summary", "PHP common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", " PHP Mathematical Calculation Skills Summary, "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP string (String) Usage summary" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.