Skip to content
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

declare(ticks=1) inside a condition #6

Closed
ninze opened this issue Jan 9, 2022 · 2 comments
Closed

declare(ticks=1) inside a condition #6

ninze opened this issue Jan 9, 2022 · 2 comments

Comments

@ninze
Copy link

ninze commented Jan 9, 2022

I was reading the docs on pcntl_async_signals and found a comment on this page:
https://www.php.net/manual/en/control-structures.declare.php

If anyone is trying to optionally use either pcntl_async_signals() when available (PHP >= 7.1) or ticks for older versions, this is not possible...at least not in a way that does NOT enable ticks for newer PHP versions. This is because there is simply no way to conditionally declare ticks. For example, the following will "work" but not in the way you might expect:

if (function_exists('pcntl_async_signals')) {
    pcntl_async_signals(true);
} else {
    declare(ticks=1);
}

While signal handlers will work with this for old and new version, ticks WILL be enabled even in the case where pcntl_async_signals exists, simply because the declare statement exists.

Then I stumbled on identical code in this repo:
https://github.com/Seldaek/signal-handler/blob/main/src/SignalHandler.php#L260

@Seldaek
Copy link
Owner

Seldaek commented Jan 12, 2022

Ah that's a good point, now that we target PHP 7.2+ for Composer I can do a new release here dropping the ticks then. Thanks

@Seldaek
Copy link
Owner

Seldaek commented Feb 17, 2022

Closed by #7

@Seldaek Seldaek closed this as completed Feb 17, 2022
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