"Online Help" about PHP timer issues

Source: Internet
Author: User
Novice Help About PHP timer issues:
I want to write a timer on PHP, but PHP does not seem to support this feature, on the Internet to check a lot of friends, but none of the methods,
I now want to through a dead loop to achieve, but also not, to help my eldest brother elder sister ...
 
  


Reply to discussion (solution)

What do you want to do?

What do you want to do? I want to use PHP to get a session value of the page, if the page is closed or the session value is invalid, execute an SQL statement, modify the current user's login status

Unfortunately, PHP does not have a timer

Unfortunately PHP does not have a timer yes, I know that PHP does not have a timer, so I want to do it by other means.

That is: knowing not to do it,?!?

Nothing is difficult, I'm afraid.

PHP is usually combined with Linux cron to do regular batch

jquery delay bar, combined with Ajax.

crontab/Scheduled Tasks

Novice Help About PHP timer issues:
I want to write a timer on PHP, but PHP does not seem to support this feature, on the Internet to check a lot of friends, but none of the methods,
I now want to through a dead loop to achieve, but also not, to help my eldest brother elder sister ...
PHP code?123456789101112 in fact your method is feasible value is not should use echo to express because PHP in the process of running the echo information is stored in the buffer before the program is run and will not output so you do not see the effect
You can replace echo with a database operation statement, such as 5 seconds to add 1 data. Can you look at it again?

And it's best not to add ignore_user_abort to the test. This will run in the background even though the browser will still continue to execute unless stopped from the process

Quote landlord fff32165 reply: Novice to ask about PHP timer problem:
I want to write a timer on PHP, but PHP does not seem to support this feature, on the Internet to check a lot of friends, but none of the methods,
I now want to through a dead loop to achieve, but also not, to help my eldest brother elder sister ...
PHP code?123456789101112 I changed echo "Test Timer" to "echo"; Is that OK? If it's not, I'm going to execute an SQL statement. Try this right now.

Reference 1 Floor Cainiaophper's reply: What do you want to do? I want to use PHP to get a session value of the page, if the page is closed or the session value is invalid, execute an SQL statement, modify the current user's login status

This idea doesn't seem to work.

You should do this in the Database user table key A valid time field the data in this field is compared with the current time to make a comparison over a certain period of time that is not the line
At the same time, write a JS timer on the page. Ajax Access Server Update effective Time field

Reference 2 floor fff32165 reply: Reference 1 floor cainiaophper reply: What do you want to do? I want to use PHP to get a session value of the page, if the page is closed or the session value is invalid, execute an SQL statement, modify the current user's login status

This idea doesn't seem to work.

You should do this in the Database user table key A valid time field by comparing the data in this field with the current time is more than a certain amount of time ... If it is with the JS timer, then my Web page closed JS does not expire it?

When the page is closed, the time will not be updated.
For example, if you have a 1-minute visit, a user with a time difference of more than 1 minutes from the current time is naturally not online.

When the page is closed, the time will not be updated.
For example, if you have a 1-minute visit, then the time difference between the active and the current time is more than 1 minutes of the user is naturally not online actually I want the effect is the webpage illegally shut down, for example, the client power off, after the webpage closed I want to execute a SQL statement change the user's login status,

In fact, I want the effect is illegal web page shut down, for example, the client power off, after the webpage closed I want to execute an SQL statement to change the user's login status,
Client pages cannot be retrieved when the server is closed unless you connect using a socket
My way is to implement the heartbeat mechanism of the socket in disguise. When the page is closed illegally, the time in your database will not be updated so you know the page is closed.
Of course, if you have to use the Login status field to use your PHP code to constantly query the database of valid time fields to determine whether to expire to modify the login status (but I think this step is not necessary, you can use the time field directly instead of the login state)

You can use Window.setinterval () and Ajax to constantly send data to a PHP file, or to request data.

You can use recursive functions to implement this function.

Specify the time to perform the database operation sleep () needs to stay on the page how can be implemented in the background to wait for the front desk to continue other operations?

  • 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.