{"id":20398928,"url":"https://github.com/chopins/php-epoll","last_synced_at":"2025-04-12T13:22:02.267Z","repository":{"id":57071122,"uuid":"210018172","full_name":"chopins/php-epoll","owner":"chopins","description":"php bindings to the linux epoll API","archived":false,"fork":false,"pushed_at":"2020-11-12T17:24:01.000Z","size":45,"stargazers_count":31,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T08:05:25.729Z","etag":null,"topics":["asynchronous","epoll","event","ffi","linux","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/chopins.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-21T16:30:13.000Z","updated_at":"2023-10-30T10:22:30.000Z","dependencies_parsed_at":"2022-08-24T14:54:25.667Z","dependency_job_id":null,"html_url":"https://github.com/chopins/php-epoll","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chopins%2Fphp-epoll","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chopins%2Fphp-epoll/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chopins%2Fphp-epoll/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chopins%2Fphp-epoll/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chopins","download_url":"https://codeload.github.com/chopins/php-epoll/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571897,"owners_count":21126536,"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":["asynchronous","epoll","event","ffi","linux","php"],"created_at":"2024-11-15T04:25:17.148Z","updated_at":"2025-04-12T13:22:02.247Z","avatar_url":"https://github.com/chopins.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# php-epoll\nPHP bindings to the linux epoll API.\n\n### Requirements\n* PHP \u003e= 7.4\n* PHP FFI extension available\n* Linux \u003e 2.6\n* toknot/ffi-extend\u003e=0.1\n\n### Install\nuse composer install:\n```\ncomposer require toknot/php-epoll\n\n```\ninclude composer autoload file : `./vendor/autoload.php`\n\n## Reference\n\n* `Epoll::__construct()`\n* `Epoll::create(int $flags)`\n\n  open an epoll file descriptor\n* `Epoll::ctl(int $op, int $fd, EpollEvent $events): int`\n\n  control interface for an epoll file descriptor\n* `Epoll::wait(EpollEvent $event, int $maxevents, int $timeout, $sigmask = null): int`\n\n  wait for an I/O event on an epoll file descriptor\n* `Epoll::getFdno(resource $file, int $type): int`\n\n  get id from file descriptor of php resource\n* `Epoll::lastErrno(): int`\n\n  get last error code\n* `Epoll::lastError(): string`\n\n  get last error message\n* `Epoll::ffi(): FFI`\n* `Epoll::initEvents($num): EpollEvent`\n* `EpollEvent::__construct(Epoll $epoll,$num)`\n* `EpollEvent::setEvent($event, $idx)`\n\n  set Epoll events\n* `EpollEvent::setData($data, $idx)`\n\n  set user data variable\n* `EpollEvent::getEvents($idx): FFI\\CData`\n\n\n\n## Simple Example\n\nphp resource to file descriptor\n```php\n$epoll = new Epoll();\n$fp = fopen(__FILE__, 'rb');\n$fdno = $epoll-\u003egetFdno($fp, Epoll::RES_TYPE_FILE);\n$fdfp = fopen(\"php://fd/$fdno\", 'rb');\necho fread($fdfp, 1024);\n```\n\nepoll example from `man epoll`\n\n```php\nconst MAX_EVENTS = 10;\nconst EXIT_FAILURE = 1;\n\n$epoll = new Epoll();\n$ev = $epoll-\u003einitEvents(MAX_EVENTS);\n$events = $epoll-\u003einitEvents();\n$stream = stream_socket_server(\"tcp://0.0.0.0:8000\", $errno, $errstr);\n$listen_sock = $epoll-\u003egetFdno($stream, Epoll::RES_TYPE_NET);\n\nfunction perror($str) {\n    fprintf(STDERR, $str);\n}\n\n$epollfd = $epoll-\u003ecreate(0);\n\n$ev-\u003esetEvent(Epoll::EPOLLIN);\n$ev-\u003esetData(['fd' =\u003e $listen_sock]);\n\nif ($epoll-\u003ectl(Epoll::EPOLL_CTL_ADD, $listen_sock, $ev) == -1) {\n    perror(\"epoll_ctl: listen_sock\");\n    exit(EXIT_FAILURE);\n}\n\nfor (;;) {\n    $nfds = $epoll-\u003ewait($events, MAX_EVENTS, -1);\n    if ($nfds == -1) {\n        perror(\"epoll_wait\");\n        exit(EXIT_FAILURE);\n    }\n\n    for ($n = 0; $n \u003c $nfds; ++$n) {\n        if ($events[$n]-\u003edata-\u003efd == $listen_sock) {\n            $conn_sock = stream_socket_accept($stream);\n            if (!$conn_sock) {\n                perror(\"accept\");\n                exit(EXIT_FAILURE);\n            }\n            stream_set_blocking($conn_sock, false);\n            $ev-\u003esetEvent(Epoll::EPOLLIN | Epoll::EPOLLET);\n            $connFdno = $epoll-\u003egetFdno($conn_sock, Epoll::RES_TYPE_NET);\n            $ev-\u003esetData(['fd' =\u003e $connFdno]);\n            if ($epoll-\u003ectl(Epoll::EPOLL_CTL_ADD, $connFdno,\n                        $ev) == -1) {\n                perror(\"epoll_ctl: conn_sock\");\n                exit(EXIT_FAILURE);\n            }\n        } else {\n            do_use_fd($events[$n]-\u003edata-\u003efd);\n        }\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchopins%2Fphp-epoll","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchopins%2Fphp-epoll","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchopins%2Fphp-epoll/lists"}