{"id":21714096,"url":"https://github.com/rstgroup/php-signal-handler","last_synced_at":"2025-04-12T19:08:33.387Z","repository":{"id":14239870,"uuid":"16947122","full_name":"rstgroup/php-signal-handler","owner":"rstgroup","description":"Singnal handling based on C signal for blocking/nonblocking php scripts","archived":false,"fork":false,"pushed_at":"2022-07-05T14:46:48.000Z","size":24,"stargazers_count":57,"open_issues_count":3,"forks_count":15,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-04-12T19:08:14.997Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rstgroup.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-18T11:46:33.000Z","updated_at":"2024-05-15T10:47:17.000Z","dependencies_parsed_at":"2022-09-05T21:41:14.319Z","dependency_job_id":null,"html_url":"https://github.com/rstgroup/php-signal-handler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstgroup%2Fphp-signal-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstgroup%2Fphp-signal-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstgroup%2Fphp-signal-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstgroup%2Fphp-signal-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rstgroup","download_url":"https://codeload.github.com/rstgroup/php-signal-handler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618277,"owners_count":21134200,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-26T00:31:16.957Z","updated_at":"2025-04-12T19:08:33.365Z","avatar_url":"https://github.com/rstgroup.png","language":"C","readme":"PHP Signal Handler\n====================\n[![Build Status](https://travis-ci.org/rstgroup/php-signal-handler.png?branch=master)](https://travis-ci.org/rstgroup/php-signal-handler)\n\nExtension uses C \u003cb\u003esignal\u003c/b\u003e function (from \u003csignal.h\u003e) to call previously defined callback, if appropriate signal has arrived (i.e SIGUSR1).\n\n### When should I use it?\n\nCould be used with \u003cb\u003e[php-amqp](https://github.com/pdezwart/php-amqp)\u003c/b\u003e to print the actual worker/consumer status (ie. message stats, last operation performed etc.) \u003cbr /\u003e\nWhat's more it is possible to \"catch\" a unix signal i.e. SIGTERM and then kill the process nicely (program won't stop untill all operations are completed). It is very useful if script operates on sensitive data which cannot be damaged.\n\n### Why don't you use pcntl_signal?\nIf a blocking method (such as ```AMQPQueue::consume()``` from [php-amqp](https://github.com/pdezwart/php-amqp)) is holding the processing thread,  then you won't be able to call \u003ci\u003e[pcntl_signal_dispatch()](http://php.net/manual/en/function.pcntl-signal-dispatch.php)\u003c/i\u003e and trigger the callbacks registered with \u003ci\u003e[pcntl_signal()](http://php.net/manual/en/function.pcntl-signal.php)\u003c/i\u003e.\n\n### Compatibility\nExtension will work only if C function ```signal``` is available (only on UNIX systems).\u003cbr/\u003e\nPHP versions supported: \u003cbr/\u003e\n* PHP 7\n* PHP 5.6\n* PHP 5.5\n* PHP 5.4\n* PHP 5.3\n\n### Example\n```php\n\u003c?php\n\nfunction getInfo($noStatus){\n\techo \"getInfo called with status $noStatus\\n\";\n}\n\n$r = attach_signal(10, 'getInfo');\nwhile(true){}\n\n?\u003e\n```\n\nSpawn the process:\n```\nphp your_script_name.php\n```\n\nKill the first process from the list:\n```\nkill -s SIGUSR1 `ps -ef | grep php | head -n1 | awk '{print $2}'`\n```\n\nAfter that steps you should see:\n```\ngetInfo called with status 10\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frstgroup%2Fphp-signal-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frstgroup%2Fphp-signal-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frstgroup%2Fphp-signal-handler/lists"}