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:4
Avg. Score:3.8 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: lusc at jiedaibao dot com
New email:
PHP Version: OS:

 

 [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-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 01:01:31 2024 UTC