Req #77377 [Opn]: No way to handle CTRL+C in Windows
| From: | nikic@php.net | Date: | Sat, 05 Jan 2019 17:21:00 +0000 |
| Subject: | Req #77377 [Opn]: No way to handle CTRL+C in Windows | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-218807@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77377&edit=1
ID: 77377
Updated by: nikic@php.net
Reported by: gadelat at gmail dot com
Summary: No way to handle CTRL+C in Windows
Status: Open
Type: Feature/Change Request
Package: Win32API related
Operating System: Windows 10
PHP Version: 7.2Git-2018-12-30 (Git)
Block user comment: N
Private report: N
New Comment:
@ab: Isn't this the same as with pctnl signal handlers? We can't run PHP code there
either, if for other reasons (not async signal safe). We handle this by registering a VM interrupt
and thus delaying execution of the PHP signal handler.
The same should be possible for Ctrl+C handling on Windows. All the groundwork in the VM is already
there, we just need the interfacing to register the VM interrupt and then call the callback.
Previous Comments:
------------------------------------------------------------------------
[2019-01-05 17:11:33] ab@php.net
Thanks for the report. Yes, it is a known issue. It is possible to catch ^C on Windows, but the
handler is invoked in a separate thread. That means, it is not safe to run PHP code within the
signal callback. If we would want to handle it, we'd have to insert some interrupts into the
VM, which would slow down the execution. For now it's most likely a won't fix issue,
I'd say.
Thanks.
------------------------------------------------------------------------
[2018-12-30 17:14:21] gadelat at gmail dot com
Description:
------------
There is currently no way how to handle CTRL+C with PHP in Windows. This makes it the only scripting
language I know that cannot handle this and pretty bad choice for writing cross platform compatible
CLI applications.
- handler registered via register_shutdown_function is not called for CTR+C
- pcntl_signal relies on PCNTL extension which isn't available on Windows
Notice that I am trying to avoid word "signal" here as you may argue there are no signals
in Windows. Developer still needs a way how to handle CTRL+C press of end user.
This is important eg. for running cleanup tasks, as not even PHP's tmpfile() cleanup logic is
executed when user aborts program via CTRL+C.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77377&edit=1