Req #77377 [Com]: No way to handle CTRL+C in Windows

From: Date: Sun, 10 Feb 2019 23:35:18 +0000
Subject: Req #77377 [Com]: No way to handle CTRL+C in Windows
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219479@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 Comment by: gadelat at gmail dot com Reported by: gadelat at gmail dot com Summary: No way to handle CTRL+C in Windows Status: Feedback Type: Feature/Change Request Package: Win32API related Operating System: Windows 10 PHP Version: 7.2Git-2018-12-30 (Git) Assigned To: ab Block user comment: N Private report: N New Comment: Here's reproducer <?php sapi_windows_set_ctrl_handler(function () { echo 'shutting down'; exit(0); }); $server = stream_socket_server('localhost:1337'); stream_set_blocking($server, false); $read = [$server]; $write = []; $except = null; stream_select($read, $write, $except, null, null); Previous Comments: ------------------------------------------------------------------------ [2019-02-10 22:14:46] ab@php.net The sapi_windows_generate_ctrl_event() can be used to send CTRL+C to a child process opened by proc_open(). It's otherwise same as one would press the keys. Thansk. ------------------------------------------------------------------------ [2019-02-10 21:51:34] gadelat at gmail dot com I did, but it uses sapi_windows_generate_ctrl_event which obviously might not match what happens when ctrl+c is pressed. ------------------------------------------------------------------------ [2019-02-10 21:22:16] ab@php.net Perhaps also check this test here http://git.php.net/?p=php-src.git;a=commitdiff;h=12bfd9a5f58c12b8f63011c130ec3bf6605ea33b#patch5 It's a bit more complex example, but it might give a better picture. Thanks. ------------------------------------------------------------------------ [2019-02-10 21:13:56] ab@php.net Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. Thanks for checking. Please show the exact code. There are internal functions that would block the execution, it would probably be same on other systems. Say a function like scanf(). The code like this, which only uses the ZVM instructions should be ok. function handler($evt) { echo "Got CTRL+C event\n"; exit; } sapi_windows_set_ctrl_handler('handler'); while(true) sleep(1); // checking the status I'd need your exact code to tell more. Thanks. ------------------------------------------------------------------------ [2019-02-10 18:31:57] gadelat at gmail dot com Allright so I did try this, unfortunately when this function is used, script hangs on CTRL+C and cannot be killed, neither specified callback is executed. Then user can kill the script (as far as I see) only via task manager. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=77377 -- Edit this bug report at https://bugs.php.net/bug.php?id=77377&edit=1

« previous php.bugs (#219479) next »