{"id":26233608,"url":"https://github.com/polonskiy/phproutine","last_synced_at":"2026-03-06T14:31:37.277Z","repository":{"id":24159043,"uuid":"27548993","full_name":"polonskiy/phproutine","owner":"polonskiy","description":"PHProutine is goroutines emulation in PHP","archived":false,"fork":false,"pushed_at":"2014-12-26T11:50:42.000Z","size":164,"stargazers_count":60,"open_issues_count":0,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-10-29T20:45:33.417Z","etag":null,"topics":["async","goroutine","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polonskiy.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":"2014-12-04T16:24:51.000Z","updated_at":"2025-01-03T15:50:35.000Z","dependencies_parsed_at":"2022-07-27T04:32:30.072Z","dependency_job_id":null,"html_url":"https://github.com/polonskiy/phproutine","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/polonskiy/phproutine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polonskiy%2Fphproutine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polonskiy%2Fphproutine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polonskiy%2Fphproutine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polonskiy%2Fphproutine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polonskiy","download_url":"https://codeload.github.com/polonskiy/phproutine/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polonskiy%2Fphproutine/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30180672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T12:39:21.703Z","status":"ssl_error","status_checked_at":"2026-03-06T12:36:09.819Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["async","goroutine","php"],"created_at":"2025-03-13T01:16:42.145Z","updated_at":"2026-03-06T14:31:37.166Z","avatar_url":"https://github.com/polonskiy.png","language":"PHP","readme":"# PHProutine\n\nPHProutine is a gouroutines emulation in PHP.\nInspired by Golang and https://gist.github.com/elimisteve/4442820\n\n# Examples\n\n## Goroutines\n\n```go\n// Steve Phillips / elimisteve\n// 2013.01.03\n\npackage main\n\nimport \"fmt\"\n\n// intDoubler doubles the given int, then sends it through the given channel\nfunc intDoubler(ch chan int, n int) {\n    ch \u003c- n*2\n}\n\nfunc main() {\n    // Make channel of ints\n    ch := make(chan int)\n    answer := make(chan string)\n\n    // Spawn 3 goroutines (basically threads) to process data in background\n    go intDoubler(ch, 10)\n    go intDoubler(ch, 20)\n    go func(a, b int) { ch \u003c- a+b }(30, 40) // Take 2 ints, write sum to `ch`\n\n    // Create anonymous function on the fly, launch as goroutine!\n    go func() {\n        // Save the 3 values passed through the channel as x, y, and z\n        x, y, z := \u003c-ch, \u003c-ch, \u003c-ch\n        // Calculate answer, write to `answer` channel\n        answer \u003c- fmt.Sprintf(\"%d + %d + %d = %d\", x, y, z, x+y+z)\n    }()\n\n    // Print answer resulting from channel read\n    fmt.Printf(\"%s\\n\", \u003c-answer)\n}\n```\n\n## PHProutines\n\n```php\n\u003c?php\n\nrequire __DIR__ . '/../src/Channel.php';\nrequire __DIR__ . '/../src/Runner.php';\n\nuse PHProutine\\Channel;\nuse PHProutine\\Runner;\n\n// intDoubler doubles the given int, then sends it through the given channel\nfunction intDoubler($ch, $n) {\n    $ch-\u003ewrite($n * 2);\n}\n\n$runner = new Runner;\n// Make channels\n$ch = new Channel;\n$answer = new Channel;\n\n// Spawn 3 PHProutines (basically PROCESSES) to process data in background\n$runner-\u003ego('intDoubler', $ch, 10);\n$runner-\u003ego('intDoubler', $ch, 20);\n$runner-\u003ego(function($a, $b) use ($ch) { $ch-\u003ewrite($a + $b); }, 30, 40);\n\n// Create anonymous function on the fly, launch as PHProutine!\n$runner-\u003ego(function() use ($ch, $answer) {\n    // Save the 3 values passed through the channel as x, y, and z\n    list($x, $y, $z) = [$ch-\u003eread(), $ch-\u003eread(), $ch-\u003eread()];\n    // Calculate answer, write to `answer` channel\n    $answer-\u003ewrite(sprintf('%d + %d + %d = %d', $x, $y, $z, $x + $y + $z));\n});\n\n// Print answer resulting from channel read\nprintf(\"%s\\n\", $answer-\u003eread());\n```\n\n## Echo server\n\n```php\n\u003c?php\n\nrequire __DIR__ . '/../src/Runner.php';\n\nuse PHProutine\\Runner;\n\n$server = stream_socket_server('tcp://127.0.0.1:8000');\n$runner = new Runner;\nwhile (true) {\n    $client = stream_socket_accept($server, -1);\n    $runner-\u003ego(function() use ($client) {\n        stream_copy_to_stream($client, $client);\n    });\n    fclose($client);\n}\n```\n\n## SleepSort\n\n```php\n\u003c?php\n\n//usage: php sleepsort.php 3 2 1 4\n\nrequire __DIR__ . '/../src/Channel.php';\nrequire __DIR__ . '/../src/Runner.php';\n\nuse PHProutine\\Channel;\nuse PHProutine\\Runner;\n\n$runner = new Runner;\n$channel = new Channel;\n\narray_shift($argv);\nforeach ($argv as $val) {\n    $runner-\u003ego(function($v) use ($channel) {\n        sleep($v);\n        $channel-\u003ewrite($v);\n    }, $val);\n}\n\nforeach ($argv as $val) {\n    echo $channel-\u003eread(), \"\\n\";\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolonskiy%2Fphproutine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolonskiy%2Fphproutine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolonskiy%2Fphproutine/lists"}