Created
April 20, 2018 11:44
-
-
Save tarunlalwani/6b4f2b81f20c781234899e62f22b0436 to your computer and use it in GitHub Desktop.
php exit handler with forking https://stackoverflow.com/questions/49759437/curl-cannot-be-killed-by-a-php-sigint-with-custom-signal-handler/49930999#49930999
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$pid = pcntl_fork(); | |
if ($pid == -1) { | |
die('could not fork'); | |
} else if ($pid) { | |
// we are the parent | |
declare(ticks=1); | |
//pcntl_async_signals(true); | |
$shutdownHandler = function () { | |
echo 'Exiting'; | |
// exit(); | |
}; | |
pcntl_signal(SIGINT, $shutdownHandler); | |
pcntl_wait($status); //Protect against Zombie children | |
} else { | |
// we are the child | |
echo "hanging now"; | |
while (true) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, 'http://blackhole.webpagetest.org'); | |
curl_exec($ch); | |
curl_close($ch); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment