How does a php timer work?

Source: Internet
Author: User
How does php timer work ??? Php timer function, in addition to the do and while functions, how can it be done? How to implement it? Php timer how to do php timer ???
Php timer function, in addition to the do and while functions, how can it be done?
How to implement it? Php timer shared:
------ Solution --------------------
Try to solve this problem on the server side or make it a trigger. if you need to do this, I think you should use sleep.
------ Solution --------------------
What is a PHP timer? Are you talking about a fixed-point trigger function?
PHP itself does not have this function, but you can use sleep () to delay the end of the script, or perform recursive calls to achieve pseudo-timing. actually, no, you can directly use ajax in JS, you can use setTimeout () of JS to regularly request PHP.
------ Solution --------------------
Php can use ignore_user_abort (TRUE); set_time_limit (0); combined with scheduled tasks. If php is deployed in linux, you can use crontab job to implement scheduled tasks.
------ Solution --------------------

Use the operating system to create scheduled tasks.
Or write the timer into the database, if you want to operate some data.

------ Solution --------------------
Reference:
Quote: reference:

Do while When timer?
Yes. Do while add sleep (); controls the number of seconds to loop once. But will it consume too much cpu?
Yes, and it may be very large.
------ Solution --------------------
Your timer should be implemented using JS ajax. Regularly and actively access the server.
------ Solution --------------------
You only know the scheduled task. Bat file. If you use php sleep for continuous execution, the server will be suspended sooner or later.
------ Solution --------------------
Reference:
Quote: reference:

What is a PHP timer? Are you talking about a fixed-point trigger function?
PHP itself does not have this function, but you can use sleep () to delay the end of the script, or perform recursive calls to achieve pseudo-timing. actually, no, you can directly use ajax in JS, you can use setTimeout () of JS to regularly request PHP.
I wrote this in the CI framework. The page uses ajax to find a method for the control layer. In this method, I want to implement a timed push function. Use do while to add sleep. But will it consume too much cpu?

Cpu consumption depends on the task to be processed in each cycle, and the pure sleep consumes almost no cpu.
However, this scheme will consume a lot of available connections on the web server.
------ Solution --------------------
Js is not used for PHP, but in HTML.
What you need to do is add ajax access control in the template file, and what PHP needs to do is to respond to the ajax request and feedback the data to js.
------ Solution --------------------
This is what the server Pushes. it is a client ajax timed request, and php responds to the returned data.

Instead of executing php push data regularly on the server.

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.