php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73806 register_shutdown_callback not catch request_terminate_timeout
Submitted: 2016-12-23 07:43 UTC Modified: -
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: lusc at jiedaibao dot com Assigned:
Status: Open Package: PCNTL related
PHP Version: 7.0.14 OS: centos
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-12-23 07:43 UTC] lusc at jiedaibao dot com
Description:
------------
I set request_terminate_timeout to 10s in php-fpm.conf, add register a shutdown callback function in my code, but when the script execute timeout, the shutdown callback function has not been trigger.    

Then , I use pcntl_signal to register a signal , like:
```
                pcntl_signal(SIGHUP, [$this, 'signal']);
                pcntl_signal(SIGTERM, [$this, 'signal']);
                pcntl_signal(SIGQUIT, [$this, 'signal']);
                pcntl_signal(SIGTSTP, [$this, 'signal']);
                pcntl_signal(SIGINT, [$this, 'signal']);

```
```
public function signal($signal)
    {
        file_put_contents('/tmp/xxx.log', time(), FILE_APPEND);
        switch ($signal) {
            case SIGTERM:
            case SIGQUIT:
            case SIGINT:
            case SIGTSTP:
                exit;
                break;
        }
    }
```

the function signal not been trigger also. but when register shutdown function and pcntl signal exist at the same time. the register shutdown callback work, if   comment out the pcntl signal, the register shutdown callback not work. why?

Test script:
---------------
<?php

register_shutdown_callback(function(){
    file_put_contents('/tmp/eee.log', time(), FILE_APPEND);
});

pcntl_signal(SIGHUP, 'signal');
pcntl_signal(SIGTERM, 'signal');
pcntl_signal(SIGQUIT, 'signal');
pcntl_signal(SIGTSTP, 'signal');
pcntl_signal(SIGINT, 'signal');

function signal($signal)
    {
        file_put_contents('/tmp/xxx.log', time(), FILE_APPEND);
        switch ($signal) {
            case SIGTERM:
            case SIGQUIT:
            case SIGINT:
            case SIGTSTP:
                exit;
                break;
        }
    }

sleep(20);
echo "end";

Expected result:
----------------
pcntl signal or register shutdown callback can catch request terminate timeout correctly 


Patches

eeiofvbw (last revision 2017-01-16 16:02 UTC by sample at email dot tst)

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat May 25 03:01:26 2019 UTC