简体   繁体   中英

php execute code before every function call

I want to introduce heartbeats to some of my scripts. I have therefore added a service class that allows to save and update a timestamp in the DB. It also keeps track of the last hearbeat and only queries the DB every 10s to prevent excessive DB calls.

Currently I need to manually add the heartbeat function call throughout my whole codebase.

Is there some way run it regularly automatically.

I found this that could be going into the right direction: https://www.php.net/manual/en/function.uopz-set-hook.php

However this requires zend and to install an extension.

Is there some other way to do it?

A function like that should really only be used in DEV, never in prod, because it will be a massive impact on execution times.

I think you are searching for something like register_tick_function .

I'll not drop a code example here, because the PHP docs do contain good ones.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM