Skip to content

pcntl not available in webserver environments causing errors #6

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

Closed
wuuti opened this issue Jan 5, 2018 · 2 comments
Closed

pcntl not available in webserver environments causing errors #6

wuuti opened this issue Jan 5, 2018 · 2 comments

Comments

@wuuti
Copy link

wuuti commented Jan 5, 2018

If the RedisSimpleLock is used in webserver environments, it will probably most of the time produce a fatal error, because the pctnl extension is not compiled in to webserver's php modules.

It is used just once to register a shutdown function for the SIGINT in the constructor, which makes sense if we want to catch a cli execution and a pressed CTRL-C for example. But that prevents usage when the pcntl extension is not available.

Better

public function __construct($identifier, Client $client, $ttl = 10000, LoggerInterface $logger = null)
    {
        $this->identifier = $identifier;
        $this->client     = $client;
        $this->ttl        = $ttl;
        $this->logger     = $logger ?: new NullLogger;
        $this->id         = mt_rand();
        register_shutdown_function($closure = $this->releaseClosure());
        if (function_exists('pcntl_signal')) {
            pcntl_signal(SIGINT, $closure);
        } 
    }
@mathroc
Copy link
Member

mathroc commented Jan 5, 2018

that’s true, however I would rather not silently ignore SIGINT on the cli. I would accept a PR with something similar to:

    public function __construct($identifier, Client $client, $ttl = 10000, LoggerInterface $logger = null, $ignoredSIGINTForSAPIs = [])
    {
        $this->identifier = $identifier;
        $this->client     = $client;
        $this->ttl        = $ttl;
        $this->logger     = $logger ?: new NullLogger;
        $this->id         = mt_rand();
        register_shutdown_function($closure = $this->releaseClosure());
        if (!in_array(php_sapi_name(), $ignoredSIGINTForSAPIs)) {
            pcntl_signal(SIGINT, $closure);
        } 
    }

so that you can explicitly say you don’t want to catch SIGINT when needed

@mathroc
Copy link
Member

mathroc commented May 23, 2019

thank you @im-bryan for working on this

@mathroc mathroc closed this as completed May 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants