Comments (4)
I still didn't figure out what the issue is with PHP7, but we can use reserve-with-timeout instead of reserve in your code, in BeanstalkController, #307
$job = $bean->reserve(1);
from yii2-beanstalk.
Hi, I have checkout the document but there is nothing about the change of behavior in ticks other than using constants.
So what is the exact issue can you post an output here?
Bests,
from yii2-beanstalk.
Thanks for the reply,
There's actually no output at all, Ctrl+C does not stop the worker at all, it's "frozen" in the reserve() mode and waits for tube to be populated before returning to the script. It looks like the issue is really coming from PHP7 and the way they deal with signals. By adding a timeout to reserve, script goes back into the while loop after the timeout to check what happened and actually "sees" the signal only at that moment.
I cannot really explain more what happens, but I can give steps to reproduce the issue (or similar issue actually):
- Get a VM with whatever distro you want and a working PHP7 setup (Ubuntu 16.04 is using PHP7 by default)
- Copy / paste the following script:
<?php
declare(ticks = 1);
pcntl_signal(SIGTERM, 'signal_handler');
pcntl_signal(SIGINT, 'signal_handler');
function signal_handler($signal)
{
switch ($signal) {
case SIGTERM:
print "Caught SIGTERM\n";
exit;
case SIGKILL:
print "Caught SIGKILL\n";
exit;
case SIGINT:
print "Caught SIGINT\n";
exit;
}
}
while (1) {
//usleep(100);
}
Try to kill the script with Ctrl+C and see that it does not work, even with ticks declared. Process gets stucked in the while loop forever. To kill it, you have to
ps aux | grep SCRIPT_NAME
kill -9 PROCESS_PID
Note: You need to kill -9, even a single kill PROCESS_PID will not get rid of it.
Now if you uncomment the usleep() portion, Ctrl+C will strop the script because it checks what it has to do before the next loop, and catches the signal at that moment. You can add pretty much anything there ($a = 1) but the script needs to do something in the loop. This behavior does not exists in PHP5.
With reserve(), it just waits for something to come in the tube, and will hang forever in case nothing comes in.
In any case, I think it's fairly easy to setup some params in the config to indicate the default timeout and use reserve with timeout, just in case. If you think this issue is not relevant, I'll just override the function as I see the need, and will appreciate your feedback.
from yii2-beanstalk.
I can confirm this behaviour since the upgrade to PHP7.
from yii2-beanstalk.
Related Issues (20)
- Limit number of tubes to be watched HOT 3
- PHP7, declaration of action is not compatible HOT 1
- Use of undefined constant STDOUT - assumed 'STDOUT' HOT 2
- Integration test HOT 3
- Releases HOT 2
- SQLSTATE[HY000] [1040] Too many connections HOT 2
- Name for actions HOT 2
- Can't use tube named index HOT 1
- Database is require while it shouldn't HOT 1
- I18n error
- How to use logger? HOT 2
- please use version tags HOT 1
- Possible race condition HOT 3
- Latest version causing insane worker CPU usage HOT 7
- How to avoid default tube listening? HOT 2
- Multiple workers HOT 3
- `db` component usage hardcode HOT 3
- Reconnection
- This software not working with last version of beanstalkd
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yii2-beanstalk.