PHP itself does not have the function of timed automatic execution, also does not support multithreading. But combined with Task Scheduler and curl, you can make up for both of these flaws in PHP, and you can run PHP scripts from any path without the Apache server environment. Knowledge Preparation
Study and application of curl:
Http://www.cnblogs.com/phphuaibei/archive/2011/09/29/2195838.html
Task Scheduler is used in Windows 7:
Add Windows Tasks section in http://www.cnblogs.com/tylerdonet/archive/2011/05/25/2057227.html
How to use Windows Task Scheduler:
Http://www.iopus.com/guides/winscheduler.htm invoke a PHP script that curl a multi-Program crawl Web page
batch.php
<?php $urls = Array (' http://www.baidu.com ', ' http://www.csdn.net ', ' http://www.google.com.h
K ');
Initialization of multithreading $MH = Curl_multi_init ();
Add each individual curl $conn = array () to multiple threads;
foreach ($urls as $key => $url) {$conn [$key]= curl_init ($url);
curl_setopt ($conn [$key],curlopt_header, 0);
curl_setopt ($conn [$key],curlopt_returntransfer, 0);
Curl_multi_add_handle ($MH, $conn [$key]);
///Execute Curl multithreaded do {$MRC = Curl_multi_exec ($MH, $active); while ($MRC = = Curlm_call_multi_perform);
while ($active && $MRC = = CURLM_OK) {if (Curl_multi_select ($MH)!=-1) {do{
$MRC = Curl_multi_exec ($MH, $active);
while ($MRC = = Curlm_call_multi_perform);
}//release each Curl thread foreach ($urls as $key => $url) {curl_error ($conn [$key]) in multiple threads;
Curl_multi_remove_handle ($MH, $conn [$key]); CurL_close ($conn [$key]); //Turn off multithreading curl_multi_close ($MH);?>
What needs to be explained is that curl in PHP is not really multithreading, but a single-threaded batch simulation of multithreaded effects. Setting Environment Variables
To facilitate the invocation of php.exe, you need to add the path to the directory where the Php.exe resides in the system variable path of the environment variable, as shown in the following illustration:
set Windows Task Scheduler
There are two ways to start a task Scheduler in a Windows 7 environment, namely:
1. Control Panel → management tools → task scheduler;
2. Start → run → enter "Task Scheduler" or "scheduled task", carriage return.
The steps to set up a scheduled task to automatically invoke a PHP script are as follows:
1. Click "Create basic Tasks" to enter the navigation
2. In the first step, enter the name and description of the scheduled task
3. Set the time the task starts
4. Set the specific action performed by the task
The PHP script called Curl is placed in the E-packing directory and is detached from the Apache server environment.
The program (or script) and parameters that are filled out here need to be validated by a command-line test.
5. When finished, open the Properties dialog box, click "Edit" in "Trigger", set the interval of automatic repeat execution
This is the process of setting up the Task Scheduler, which will then pop up a php.exe dos window every 5 minutes, and the setting is successful.