curl / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: CURL cannot be killed by a PHP SIGINT with custom signal handler

From: Rainer Canavan <rainer+curlusers_at_7val.com>
Date: Wed, 11 Apr 2018 11:45:03 +0200

On Tue, Apr 10, 2018 at 8:02 PM, Jonathan Bull <jonathanbull_at_gmail.com> wrote:
> I have a PHP command line app with a custom shutdown handler:

[...]

> If I kill the script with `Ctrl+C` while a CURL request is in progress, it has no effect. The command just hangs. If I remove my custom shutdown handler, `Ctrl+C` kills the CURL request immediately.
>
>
> Why is CURL unkillable when I define a `SIGINT` handler? Thanks!

That appears to be a problem with the standard php curl bindings. It
doesn't happen with pecl_http (https://pecl.php.net/package/pecl_http)

    declare(ticks=1);

   $shutdownHandler = function () {
       echo 'Exiting';
       exit();
   };

   pcntl_signal(SIGINT, $shutdownHandler);

   while (true) {
       $client = new http\Client();
       $client->enqueue(new http\Client\Request("GET",
"http://blackhole.webpagetest.org"));
       try {
           $client->send();
       } catch (Exception $e) {
           print("\n".$e->getMessage()."\n");
       }
   }

rainer
_______________________________________________
https://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2018-04-11