Home >Backend Development >PHP Tutorial >Detailed explanation of several methods of executing tasks regularly in PHP
The two key functions: ignore_user_abort(true), the function of this function is that the following code will be executed regardless of whether the client closes the browser. set_time_limit(0), the function of this function is to cancel the execution time of the PHP file. If there is no such function, the default PHP execution time is 30 seconds, which means that after 30 seconds, the file will say goodbay. In addition, usleep supports Windows operating system after PHP5.0. When we are doing a PHP email sending problem, we often encounter this problem, that is, users subscribe to some information that needs to be sent to the user's mailbox regularly. I searched the Internet and found that there are not many articles like this. This article introduces A method implemented using PHP. The author has not been using PHP for a long time. Everyone is welcome to PP. 1. To achieve scheduled sending, the main problem to solve is timing. What kind of if should be added when writing a program? If a certain time = a certain time, then the page will be sent. However, to implement this process, the problem is that we have to execute this page before it can be sent. Therefore, the main problem to be solved is how to deliver the goods when the time comes The server executes this page regularly, which seems to be difficult to implement. 2. Open the php manual and find the command line mode of PHP. You can study it. 3. Solution: 1. On the Windows platform, you can associate the double-click attributes of cliphp.exe and .php files, or you can write a batch file to execute scripts with PHP. We put the written program in a directory as follows:
Write a bat file.
Save it as: timesend.bat and place it in the @D:phpcliphp.exe directory Add a scheduled task in window and that’s it! 5. Explanation. 1. The template I use to send emails is stored in the database. There are two other email sending classes that are not provided. If you want, you can contact me. 2. Use absolute paths when using requrie_once. 3. PHP's command line mode allows PHP scripts to run completely independently of the WEB server, so it can reduce the load on the server when sending a large number of emails. 4. Once again, I recommend that you read the PHP manual Chapter 23. PHP command line mode. Actually, this is not a real way to automatically send emails, but in the WEB mode without desktop applications, this may be a better way~! , I want a system that truly realizes automatic sending of emails, in the service There is still a desktop application for support on the server side! So this automatic sending of emails is just a way to implement PHP programs to send emails!
|