On the automatic operation method of PHP file _php skill

Source: Internet
Author: User
Tags php programming php regular expression regular expression

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.