search
HomeBackend DevelopmentPHP TutorialWindows executes PHP regularly

Windows executes PHP regularly

Mar 10, 2018 am 10:28 AM
phpwindowstiming

I believe that many readers (PHP enthusiasts) often complain during the process of work and study: How to make PHP automatically send emails at regular intervals in WIN? ? How to make MYSQL realize automatic backup without worries? ? Of course it can be done entirely manually, but the operation seems a bit too cumbersome! Don't worry, this problem can be easily solved by using the system's task scheduler (called a scheduled task in Windows 98). This feature is often overlooked or never thought of by many users :).

The so-called task plan is to automatically call the application program set by the user in advance by the computer, thereby simplifying the user's operation. Using the task scheduler of Windows 2000 (equivalent to the cron program under *NIX, which will not be described in detail here), we can arrange for any script, program or document to run at the most appropriate time to meet our own needs. The following takes Windows 2000 as an example.

Specifically, if we need to use the task scheduler to run automatically, we should perform the following steps:

1. Click the "Start" button, and then select "Programs" → "Accessories" → "System Tools" → "Task Schedule" (or "Settings" → "Control Panel" → "Task Schedule") to start the Windows 2000 task schedule management program.

2. Double-click the "Add Task Plan" icon in the "Task Plan" window to start the system's "Task Plan Wizard", then click the "Next" button and select the desired program from the given program list. Automatically run the application and click the "Next" button.
Set an appropriate task schedule name and select the time frequency to automatically perform this task (such as daily, weekly, monthly, one-time, every time you start the computer, every time you log in, etc.), then click "Next " button.
At this time, the system will ask the user to set the specific time for the program to run, such as what day, what time, what time period it can run, etc. We only need to set it according to our own needs.

4. Next, the system will ask the user to set an appropriate username and password (as shown in Figure 5) so that the system can run automatically in the future.

5. Finally, we only need to click the "Finish" button to add the corresponding task to the Windows 2000 Task Scheduler. After that, it will automatically "remember" the task once the system time and If the relevant conditions match the plan set by the user, it will automatically call the application specified by the user, which is very convenient (every time you start Windows 2000, the task scheduler will automatically start and run in the background to ensure that the user's plan can be scheduled on time. implement).

Now let’s test whether the task we just created is successful. Right-click the “php” program icon (as shown in Figure 6) and select “Run” in the pop-up menu. Under normal circumstances, the program icon can be started normally as long as it is activated in this way. If the operation fails, you can check whether the user and password are set correctly, and confirm whether the "Task Scheduler" service has been started. I turned it off to save system resources, which caused the operation to fail, which cost me a long time to find. In addition, you can also check the "System Log" to see what caused the operation to fail.

Okay, after talking about so many tasks planning applications, let’s get to the point. Two examples will be introduced below:

1. Let PHP run regularly!
1. Edit the following code and save it as test.php:

<?php 
 $fp = @fopen("test.txt", "a+"); 
 fwrite($fp, date("Y-m-d H:i:s") . " 让PHP定时运行吧!/n"); 
 fclose($fp); 
 ?>

2. Add a task plan and enter the command in this step (as shown in Figure 2): D:/php4 /php.exe -q D:/php4/test.php

3. Set the time to run every 1 minute, and then run the task.

4. Now let’s see if the content of the d:/php4/test.txt file is successful. If the content is as shown below, congratulations on your success.

2003-03-03 11:08:01 Let PHP run regularly!
2003-03-03 11:09:02 Let PHP run regularly!
2003-03-03 11:10:01 Let PHP run regularly!
2003-03-03 11:11:02 Let PHP run regularly!

2. Make it possible for MYSQL to realize automatic backup!
1. Edit the following code and save it as backup.php. If you want to compress it, you can copy a rar.exe:

<?php 
 if ($argc != 2 || in_array($argv[1], array(&#39;--help&#39;, &#39;-?&#39;))) { 
 ?>
backup  Ver 0.01, for Win95/Win98/WinNT/Win2000/WinXP on i32 
 Copyright (C) 2000 ptker All rights reserved. 
 This is free software,and you are welcome to modify and redistribute it 
 under the GPL license 
 PHP Shell script for the backup MySQL database. 
 Usage: <?php echo $argv[0]; ?> <option> 
   <option> can be database name you would like to backup. 
   With the --help, or -? options, you can get this help and exit. 
 <?php 
 } else { 
     $dbname = $argv[1]; 
     $dump_tool = "c://mysql//bin//mysqldump"; 
     $rar_tool = "d://php4//rar"; 
     @exec("$dump_tool --opt -u user -ppassword $dbname > ./$dbname.sql"); 
     @exec("$rar_tool a -ag_yyyy_mm_dd_hh_mm $dbname.rar $dbname.sql"); 
     @unlink("$dbname.sql"); 
     echo "Backup complete!"; 
 } 
 ?>

2、添加一个任务计划,在(如图2所示)这一步输入命令:
   D:/php4/php.exe -q D:/php4/backup.php databasename
3、时间设置为每天运行一次,然后运行这个任务。
4、最后会在d:/php4/目录下生成一个以数据库名和当前时间组成的rar文件。
5、恭喜你!大功告成了!
    当然备份方式有很多种,读者可按照自己喜欢的去做!
以上是原著.结合本人实贱,补充说明如下:

1. 如果出现错误:
           在试着设置任务帐户信息时出现错误
   指定的错误是:
   0x80070005:拒绝访问
   您没有运行所请求的操作的权限

在上面'"4.接下来系统将会要求用户设置适当的用户名及密码(如图5所示),以便系统今后能自动加以运行".这里最好用"system"用户,密码可为空.如图:

Windows executes PHP regularly

这个system的权限非常之高,比你的administrator还要高,所以你在运行命令的时候千万不要乱来,这个可是什么提示都没有就会无条件执行的,这个权限下你kill核心进程都行.

2.上面'"'2、添加一个任务计划,在(如图2所示)这一步输入命令:D:/php4/php.exe -q D:/php4/test.php",正确形式应为  '"D:/php4/php.exe'" -q '"D:/php4/test.php'"  ,即路径要用双引号括住.

相关推荐:

window下如何实现定时执行php脚本

windows定时执行PHP的技巧 windows10 下载 windows优化大师 windows7 64位旗舰

Linux下crontab定时执行PHP程序的方法

The above is the detailed content of Windows executes PHP regularly. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP's Purpose: Building Dynamic WebsitesPHP's Purpose: Building Dynamic WebsitesApr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP: Handling Databases and Server-Side LogicPHP: Handling Databases and Server-Side LogicApr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

How do you prevent SQL Injection in PHP? (Prepared statements, PDO)How do you prevent SQL Injection in PHP? (Prepared statements, PDO)Apr 15, 2025 am 12:15 AM

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

PHP and Python: Code Examples and ComparisonPHP and Python: Code Examples and ComparisonApr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP in Action: Real-World Examples and ApplicationsPHP in Action: Real-World Examples and ApplicationsApr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: Creating Interactive Web Content with EasePHP: Creating Interactive Web Content with EaseApr 14, 2025 am 12:15 AM

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python: Comparing Two Popular Programming LanguagesPHP and Python: Comparing Two Popular Programming LanguagesApr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

The Enduring Relevance of PHP: Is It Still Alive?The Enduring Relevance of PHP: Is It Still Alive?Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool