Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use PHP to treat a continuous record within N seconds as a record

Shulou Source: shulou.com Published: 2022-06-02 07:32:29 11月14日 Update

This article introduces the knowledge of "how to use PHP to treat continuous records within N seconds as a record". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

It's interesting: PHP regards continuous records within N seconds as a record.

Now it's 11:34:00 seconds, and I'm sending a "hello," to the system.

02 seconds-"I" 03 seconds-"am" 04 seconds-"php_yt"

When sending "hello", the system saves a record

Sendtime:1638589060,text:hello

Within 5 seconds, the system is treated as a record, that is,

Sendtime:1638589060,text:hello, i am php_yt

It can be implemented through the following

$now = time (); $now2 = intval ($now / 5) * 5

Test code

Echo $now = time (); / / 1638589533echo PHP_EOL;echo $now / 5 intval / 327717906.6echo PHP_EOL;echo $custom_time = intval ($now / 5) * 5 Tring hand 1638589530

If hello, the time of this record is 1638589530, then the current timestamp 1638589533 is also regarded as the same time as hello.

Of course, it can also be adjusted from 5 seconds to 10 seconds, and the principle is

Echo $now / 5; / / 327717906.6 forward 0.2 decimal point per second, rounded and ignored

For 10 seconds, the decimal point is forward 0.1, rounded and ignored.

However, the above has bug, which can convert the sending time over a period of time to custom_time merging.

This is the end of the content of "how to use PHP to treat continuous records within N seconds as a record". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Time system content decimal decimal more knowledge faceted practical identical successful and then interesting code principle dilemma reality that is the situation I to Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple NVidia OPPO Reno Redmi Microsoft