polonskiy / Phproutine
Licence: mit
PHProutine is goroutines emulation in PHP
Stars: ✭ 50
Projects that are alternatives of or similar to Phproutine
Routine
go routine control, abstraction of the Main and some useful Executors.如果你不会管理Goroutine的话,用它
Stars: ✭ 40 (-20%)
Mutual labels: goroutine
Gsysint
Golang (as of 1.12.5) runtime internals that gives you an access to internal scheduling primitives. Park Gs, read IDs. (for learning purposes)
Stars: ✭ 44 (-12%)
Mutual labels: goroutine
Cvdm.errorhandling
[DEPRECATED, use FsToolkit.ErrorHandling] AsyncResult and Result computation expressions and helper functions for error handling in F#
Stars: ✭ 47 (-6%)
Mutual labels: async
Preact Cli Plugin Async
Preact CLI plugin that adds converts async/await to Promises.
Stars: ✭ 44 (-12%)
Mutual labels: async
Node Qiniu Sdk
七牛云SDK,使用 ES2017 async functions 来操作七牛云,接口名称与官方接口对应,轻松上手,文档齐全
Stars: ✭ 44 (-12%)
Mutual labels: async
Fgbase
Ready-send coordination layer on top of goroutines.
Stars: ✭ 45 (-10%)
Mutual labels: goroutine
Fastapi
FastAPI Tutorials & Deployment Methods to Cloud and on prem infrastructures
Stars: ✭ 41 (-18%)
Mutual labels: async
Async
An awesome asynchronous event-driven reactor for Ruby.
Stars: ✭ 1,000 (+1900%)
Mutual labels: async
Uvicorn Gunicorn Fastapi Docker
Docker image with Uvicorn managed by Gunicorn for high-performance FastAPI web applications in Python 3.6 and above with performance auto-tuning. Optionally with Alpine Linux.
Stars: ✭ 1,014 (+1928%)
Mutual labels: async
Protobuffer
A simple wrapper library for protobuf-net with async, gzip and less boilerplate.
Stars: ✭ 50 (+0%)
Mutual labels: async
PHProutine
PHProutine is a gouroutines emulation in PHP. Inspired by Golang and https://gist.github.com/elimisteve/4442820
Examples
Goroutines
// Steve Phillips / elimisteve
// 2013.01.03
package main
import "fmt"
// intDoubler doubles the given int, then sends it through the given channel
func intDoubler(ch chan int, n int) {
ch <- n*2
}
func main() {
// Make channel of ints
ch := make(chan int)
answer := make(chan string)
// Spawn 3 goroutines (basically threads) to process data in background
go intDoubler(ch, 10)
go intDoubler(ch, 20)
go func(a, b int) { ch <- a+b }(30, 40) // Take 2 ints, write sum to `ch`
// Create anonymous function on the fly, launch as goroutine!
go func() {
// Save the 3 values passed through the channel as x, y, and z
x, y, z := <-ch, <-ch, <-ch
// Calculate answer, write to `answer` channel
answer <- fmt.Sprintf("%d + %d + %d = %d", x, y, z, x+y+z)
}()
// Print answer resulting from channel read
fmt.Printf("%s\n", <-answer)
}
PHProutines
<?php
require __DIR__ . '/../src/Channel.php';
require __DIR__ . '/../src/Runner.php';
use PHProutine\Channel;
use PHProutine\Runner;
// intDoubler doubles the given int, then sends it through the given channel
function intDoubler($ch, $n) {
$ch->write($n * 2);
}
$runner = new Runner;
// Make channels
$ch = new Channel;
$answer = new Channel;
// Spawn 3 PHProutines (basically PROCESSES) to process data in background
$runner->go('intDoubler', $ch, 10);
$runner->go('intDoubler', $ch, 20);
$runner->go(function($a, $b) use ($ch) { $ch->write($a + $b); }, 30, 40);
// Create anonymous function on the fly, launch as PHProutine!
$runner->go(function() use ($ch, $answer) {
// Save the 3 values passed through the channel as x, y, and z
list($x, $y, $z) = [$ch->read(), $ch->read(), $ch->read()];
// Calculate answer, write to `answer` channel
$answer->write(sprintf('%d + %d + %d = %d', $x, $y, $z, $x + $y + $z));
});
// Print answer resulting from channel read
printf("%s\n", $answer->read());
Echo server
<?php
require __DIR__ . '/../src/Runner.php';
use PHProutine\Runner;
$server = stream_socket_server('tcp://127.0.0.1:8000');
$runner = new Runner;
while (true) {
$client = stream_socket_accept($server, -1);
$runner->go(function() use ($client) {
stream_copy_to_stream($client, $client);
});
fclose($client);
}
SleepSort
<?php
//usage: php sleepsort.php 3 2 1 4
require __DIR__ . '/../src/Channel.php';
require __DIR__ . '/../src/Runner.php';
use PHProutine\Channel;
use PHProutine\Runner;
$runner = new Runner;
$channel = new Channel;
array_shift($argv);
foreach ($argv as $val) {
$runner->go(function($v) use ($channel) {
sleep($v);
$channel->write($v);
}, $val);
}
foreach ($argv as $val) {
echo $channel->read(), "\n";
}
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].