PHP implements the code that Windows Task Scheduler executes regularly and extends

Source: Internet
Author: User

Task planning in our daily work development, there is great use, sometimes the project needs a large number of data updates inserted into the database, so we can save resources, we need to calculate the timing period automatically, for this, we need the PHP task to implement, Then we will introduce to you today PHP implementation of Windows Task Scheduler timed execution!

In addition, after finding the solution of this kind of problem on the Internet, we can also use PHP's Ignore_user_abort () function, which has not been used, so the PHP official website is introduced in this way.

int Ignore_user_abort ([string $value])

Sets whether the execution of the script is interrupted when the client disconnects, and when PHP executes as a command line script, when the script terminal ends, the script is not aborted immediately, unless value is set to TRUE, the script will be aborted if any characters are output.

The personal understanding is that the code block of this function continues to execute without being executed through the browser, but in the command-line manner. In this blog post, there is a concrete way to implement this function.

Here is an example of a test.

Windows batch File

Create a new text document, and write the following code, saved as a. bat file.

E: "E:\PHP\wamp\bin\php\php5.5.12\php.exe"-F "E:\PHP\wamp\www\write.php"

PHP run mode

Usually executes the PHP code, is through the browser to the server request way execution, this mode of operation is called module mode. Module mode is integrated in the form of a MOD_PHP5 module, at which point the MOD_PHP5 module is to receive PHP file requests from Apache, process the requests, and then return the processed results to Apache. If we configure the PHP module (MOD_PHP5) in its configuration file before Apache starts, the PHP module registers the apache2 ap_hook_post_config hook and starts the module to accept PHP file requests when Apache starts.

When we use the Php.exe execution, is the CLI mode, this blog post on PHP Four operating mode is elaborated in detail.

Php.exe

PHP command Line Executor Php.exe is very powerful, in the Windows environment to configure the system variable path value can be directly in the DOS window interface directly run PHP script file, this article has a specific configuration method.

The php.exe here is one of three PHP-related EXE files in the PHP installation directory, Php-cgi.exe, Php-win.exe

Php-cgi.exe is provided for use as CGI, and is typically used to parse PHP scripts in a Windows environment by CGI, often used to run PHP Web sites under IIS, except that the following HTTP headers are automatically exported before the file outputs all content.

X-powered-by:php/5.2.5content-type:text/html

Php-win.exe can also execute PHP files, the difference is large open the console, do not display the output content. It can be used to write file processing, Web services and other programs without displaying the interface.

PHP Code Execution

<?PHP$FP = @fopen ("E:/php/wamp/www/test.txt", "A +"), fwrite ($FP, "Auto-broadcast time: \ n". Date ("y-m-d h:i:s"); fclose ($FP);

Here the file path must be absolute path , because there is no Apache or IIS such server, in addition to some server-based variables can not be used, such as $_server, etc., there is very likely to occur a variety of unpredictable errors.

Create a task schedule

This Baidu a bit can make a lot of, I test the use is Windows7.
Start – "Accessories –" System Tools – "Task Scheduler
Double-click Create Task

Create name and set Execute permissions

Set start time and repeat task interval time

Select the script path that was written

You've created the Task Scheduler here.
Here is the effect of the execution

Summarize:

The implementation of Windows Task Scheduler, I believe many small partners know how to use PHP to achieve, and hope to help you work!

Related recommendations:

Sample code sharing for PHP scheduled tasks


How does PHP implement scheduled execution tasks?


php analysis of the implementation of scheduled tasks

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.