-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running a task every few seconds #5098
Comments
Swoole\Runtime::enableCoroutine($flags = SWOOLE_HOOK_ALL);
$connection = null;
$timerId = Timer::tick(5000, function () : void {
try {
write_log('Checking stale: '.(time() - Database::getLastAccessedTime()));
if (time() - Database::getLastAccessedTime() > 60) {
global $connection;
write_log('Reconnecting database...');
$connection = Database::connect();
}
} catch (\Throwable $e) {
write_log($e::class.': '.$e->getMessage());
}
});
Swoole\Event::wait(); |
You can not run blocking operations in the |
Thank you very much. What you are saying is that if I put I made the changes as suggested, but it is still not triggering, for some reason :( |
The PHP blocking functions will turn to non-blocking function if you put You can execute your code in a non docker environment to find where the problem is. |
Hello,
I'm trying to have a task run every 5 seconds, to prevent the database connection from becoming stale.
However, for some reason, this doesn't seem to run, or gets stuck, until I restart the docker container, where it appears to run and log at that point.
Is it because I'm running blocking operations here?
I also tried:
but this doesn't seem to run at all.
I'm also confused how to run
Coroutine
, withcreate
,run
andresume
.. :)Can I run blocking operations in
Scheduler
and/orCoroutine
?What's the best way to run a simple task every 5 seconds (or every minute), that accepts blocking operations, and has access to the variables in the global scope, such as the global database connection?
Thank you very much!
The text was updated successfully, but these errors were encountered: