Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
c955161
PHP IDE documentation/stubs - WIP
TheTechsTech Jan 9, 2020
25b3f4e
create/add interface stubs, with correct return type and parameter ty…
TheTechsTech Jan 11, 2020
278d235
corrections, have the return types as indicated by this library
TheTechsTech Jan 12, 2020
62c2674
corrections, update some examples for proper operations under windows…
TheTechsTech Jan 12, 2020
ba20022
Completed - added/merged in phpstorm stubs, but still needs updating …
TheTechsTech Jan 12, 2020
aa6f1c5
more doc updates of types, add example of sendfile on server poll, fa…
TheTechsTech Jan 13, 2020
c75b2d7
corrections, adding more examples of spawn with signal/process_kill, …
TheTechsTech Jan 13, 2020
c561e6e
Update, some POSIX signals really working on Windows!
TheTechsTech Jan 14, 2020
d97575e
Add signal constants, mainly for Windows
TheTechsTech Jan 15, 2020
1d9c0a5
some stub updates, interface, functions and types
TheTechsTech Jan 16, 2020
5652c31
add some quick install docs
TheTechsTech Jan 17, 2020
17ed529
Update README.md
TheTechsTech Feb 9, 2020
1cd12b1
Merge remote-tracking branch 'upstream/master'
TheTechsTech Feb 15, 2020
917f027
Update UVFunctions.php
TheTechsTech Feb 15, 2020
e346dad
Update UVFunctions.php
TheTechsTech Feb 15, 2020
a7e6e2f
Merge remote-tracking branch 'upstream/master'
TheTechsTech Feb 15, 2020
9ee2a0b
Merge remote-tracking branch 'upstream/master'
TheTechsTech Feb 15, 2020
f65de35
Merge remote-tracking branch 'upstream/master'
TheTechsTech Feb 15, 2020
9e5e3f3
Some updates of types to match current release/commits
TheTechsTech Feb 16, 2020
6165951
Update UVFunctions.php
TheTechsTech Feb 16, 2020
41138f2
more type updates/corrections, and move docblocks around
TheTechsTech Feb 16, 2020
0ff3c90
Merge remote-tracking branch 'upstream/master'
TheTechsTech Feb 16, 2020
eae0202
more type updates/corrections
TheTechsTech Feb 16, 2020
d60a999
UV handles are final classes, not interfaces; added missing UVLock
bwoebi Feb 16, 2020
924fc38
Merge remote-tracking branch 'upstream/master'
TheTechsTech Feb 16, 2020
cdbeff2
more type updates/corrections
TheTechsTech Feb 16, 2020
b652d49
Completed docblocks, and type updates
TheTechsTech Feb 16, 2020
dd82e9e
Update UVInterfaces.php
TheTechsTech Feb 16, 2020
c5ae598
Merge remote-tracking branch 'upstream/master'
TheTechsTech Feb 16, 2020
ae0ec75
There are no methods on UV class; marked abstract
bwoebi Feb 16, 2020
09438ab
Update README.md
TheTechsTech Feb 16, 2020
88be8ab
Update UVFunctions.php
TheTechsTech Feb 16, 2020
7899962
Update UVFunctions.php
bwoebi Feb 16, 2020
b984f2e
update rename `uv_handle_type` to `uv_handle_get_type`
TheTechsTech Feb 17, 2020
23e4c47
add uv_fs_scandir
TheTechsTech Feb 17, 2020
ed6f29a
Update README.md
TheTechsTech Feb 17, 2020
c14ed61
various corrections
TheTechsTech Feb 17, 2020
5d70b07
Update UVFunctions.php
TheTechsTech Feb 18, 2020
49f53f4
Update UVFunctions.php
TheTechsTech Feb 18, 2020
d8ae9ad
Merge remote-tracking branch 'upstream/master'
TheTechsTech Feb 18, 2020
5fe7135
add missing functions
TheTechsTech Feb 18, 2020
d6263ea
Update README.md
TheTechsTech Feb 18, 2020
542d3d7
corrections and file rename
TheTechsTech Feb 20, 2020
9bde7ba
Update UVFunctions.php
TheTechsTech Feb 24, 2020
e6bc597
add missing function
TheTechsTech Feb 24, 2020
d88e5b2
callback signature fixes
TheTechsTech Feb 25, 2020
4ad3a14
updates, add missing handle
TheTechsTech Feb 25, 2020
03c2fa7
fix `uv_fs_scandir` call signature
TheTechsTech Mar 4, 2020
4c1cb0a
corrections - resource to handle
TheTechsTech Mar 19, 2020
b21c83d
Update UVFunctions.php
TheTechsTech Mar 23, 2020
8e4805f
add link to doc stubs
TheTechsTech Apr 6, 2020
b0f2474
Update UVFunctions.php
TheTechsTech Apr 11, 2020
a0d1567
Update UV.php
TheTechsTech Apr 14, 2020
0202b0a
update `uv_fs_event_init` to indicate the behavior combines `uv_fs_ev…
TheTechsTech Apr 17, 2020
f2f085d
corrections for uv_timer_start
TheTechsTech Apr 21, 2020
b19bdc5
doc update from https://github.com/libuv/libuv/pull/2803
TheTechsTech Apr 28, 2020
8d3f05c
indicate network socket/stream tests should be skipped as broken on W…
TheTechsTech May 1, 2020
b0c5b1e
Update UV.php
TheTechsTech May 7, 2020
472877d
Update UVFunctions.php
TheTechsTech May 24, 2020
52de354
Merge remote-tracking branch 'upstream/master'
TheTechsTech Oct 13, 2020
a3b9368
Merge remote-tracking branch 'upstream/master'
TheTechsTech Feb 3, 2021
9f3b868
Merge remote-tracking branch 'upstream/master'
TheTechsTech Feb 3, 2021
6858e5f
Update README.md
TheTechsTech Feb 3, 2021
f3a3eea
Merge branch 'master' of https://github.com/techno-express/php-uv
TheTechsTech Feb 3, 2021
016b311
Merge remote-tracking branch 'upstream/master'
TheTechsTech Mar 18, 2021
f811c15
allow auto embed by build process
TheTechsTech Jun 16, 2021
0319707
Merge remote-tracking branch 'upstream/master'
TheTechsTech Apr 6, 2022
b318453
fix php_uv_address_to_zval update tests & examples
TheTechsTech Sep 23, 2022
93243cf
Update 600-pipe_bind.phpt
TheTechsTech Sep 29, 2022
0dc7cb7
more `uv_queue_work()` examples
TheTechsTech Mar 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,937 changes: 76 additions & 2,861 deletions README.md

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions examples/fs.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
throw new Exception("read error");
}

uv_fs_close(uv_default_loop(), $stream, function(){
});
} else {
echo $data;
}
uv_fs_close(uv_default_loop(), $stream, function () {
});
} else {
echo $data;
}
});
});
});

Expand Down
59 changes: 59 additions & 0 deletions examples/listen.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
class TcpServer
{
private $loop;
private $tcp;

public function __construct($loop)
{
$this->loop = $loop;
$this->tcp = uv_tcp_init($loop);
}

public function bind(string $address, int $port)
{
uv_tcp_bind($this->tcp, uv_ip4_addr($address, $port));
}

public function listen()
{
uv_listen($this->tcp, 128, function ($server, $status) {

$client = uv_tcp_init($this->loop);
uv_accept($server, $client);

uv_read_start($client, function ($socket, $buffer) {
echo 'OK', PHP_EOL;
uv_close($socket);
});
});
}

public function close()
{
if ($this->tcp instanceof UV) {
uv_close($this->tcp);
}
}
}

$loop = uv_loop_new();

$tcpServer = new TcpServer($loop);
$tcpServer->bind('127.0.0.1', 9876);
$tcpServer->listen();

$closed = 0;
for ($i = 0; $i < 4; $i++) {
$c = uv_tcp_init($loop);
uv_tcp_connect($c, uv_ip4_addr('127.0.0.1', 9876), function ($stream, $stat) use (&$closed, $tcpServer) {
$closed++;
uv_close($stream);

if ($closed === 4) {
$tcpServer->close();
}
});
}

uv_run($loop, UV::RUN_DEFAULT);
7 changes: 4 additions & 3 deletions examples/pipe.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

$pipe = uv_pipe_init(uv_default_loop(), 0);
uv_pipe_open($pipe, 1);
$pipe = uv_tty_init(uv_default_loop(), \STDOUT, 0);
//$pipe = uv_pipe_init(uv_default_loop(), 0);
//uv_pipe_open($pipe, 1);
//uv_pipe_bind($pipe,"/tmp/hoge.sock");

uv_write($pipe, "Hello", function($pipe, $buf) {
uv_write($pipe, "Hello", function ($pipe, $buf) {
echo 1;
uv_close($pipe);
});
Expand Down
8 changes: 4 additions & 4 deletions examples/poll.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?php

$socket = stream_socket_server("tcp://0.0.0.0:9999", $errno, $errstr);
$socket = stream_socket_server("tcp://127.0.0.1:9999", $errno, $errstr);
stream_set_blocking($socket, 0);

$poll = uv_poll_init(uv_default_loop(), $socket);

uv_poll_start($poll, UV::READABLE, function($poll, $stat, $ev, $socket) {
uv_poll_start($poll, UV::READABLE, function ($poll, $stat, $ev, $socket) {
echo "parent poll:\n";
var_dump($stat);
$conn = stream_socket_accept($socket);

$pp = uv_poll_init(uv_default_loop(), $conn);
uv_poll_start($pp, UV::WRITABLE, function($poll, $stat, $ev, $conn) {
uv_poll_start($pp, UV::WRITABLE, function ($poll, $stat, $ev, $conn) {
echo " cb";
var_dump($stat);
var_dump($conn);

uv_poll_stop($poll);
uv_fs_write(uv_default_loop(), $conn, "Hello World", -1, function($conn, $nwrite) {
uv_fs_write(uv_default_loop(), $conn, "Hello World", -1, function ($conn, $nwrite) {
var_dump($conn);
fclose($conn);
});
Expand Down
35 changes: 35 additions & 0 deletions examples/poll_sendfile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

$socket = stream_socket_server("tcp://127.0.0.1:9999", $errno, $errstr);

$poll = uv_poll_init(uv_default_loop(), $socket);

uv_poll_start($poll, UV::READABLE, function ($poll, $stat, $ev, $socket) {
echo "parent poll:\n";
var_dump($stat);
$conn = stream_socket_accept($socket);

$pp = uv_poll_init(uv_default_loop(), $conn);
uv_poll_start($pp, UV::WRITABLE, function ($poll, $stat, $ev, $conn) {
echo " connected callback has: stat -";
print_r($stat);
echo " event -";
print_r($ev);
echo " poll -";
print_r($poll);

echo " stream_get_meta_data(conn) -";
print_r(\stream_get_meta_data($conn));
uv_poll_stop($poll);
uv_fs_open(uv_default_loop(), __FILE__, UV::O_RDONLY, 0, function ($read_fd) use ($conn) {
uv_fs_fstat(uv_default_loop(), $read_fd, function ($r, $stat) use ($conn) {
uv_fs_sendfile(uv_default_loop(), $conn, $r, 0, $stat['size'], function ($conn) {
fclose($conn);
uv_stop(uv_default_loop());
});
});
});
});
});

uv_run();
40 changes: 40 additions & 0 deletions examples/process_kill.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

$in = uv_pipe_init(uv_default_loop(), ('/' == \DIRECTORY_SEPARATOR));
$out = uv_pipe_init(uv_default_loop(), ('/' == \DIRECTORY_SEPARATOR));

echo "Hello, ";

$stdio = array();
$stdio[] = uv_stdio_new($in, UV::CREATE_PIPE | UV::READABLE_PIPE);
$stdio[] = uv_stdio_new($out, UV::CREATE_PIPE | UV::WRITABLE_PIPE);

$flags = 0;
$pid = uv_spawn(
uv_default_loop(),
"php",
array('-r', 'echo "World! ";'),
$stdio,
__DIR__,
[],
function ($process, $stat, $signal) {
if ($signal == 9) {
echo "The process was terminated with 'SIGKILL' or '9' signal!";
}

uv_close($process, function () {
});
},
$flags
);

uv_process_kill($pid, 9);

uv_read_start($out, function ($out, $nread, $buffer) {
echo $buffer;

uv_close($out, function () {
});
});

uv_run();
7 changes: 3 additions & 4 deletions examples/queue.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php
$loop = uv_default_loop();

$queue = uv_queue_work($loop, function(){
$queue = uv_queue_work($loop, function () {
echo "[queue]";
}, function(){
}, function () {
echo "[finished]";
});


uv_run();

uv_run($loop);
33 changes: 33 additions & 0 deletions examples/queue_2_threads.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

$loop = uv_default_loop();
$completed = false;
uv_queue_work($loop, function () use (&$completed) {
while (!$completed) {
echo "[queue2]";
usleep(1);
}
}, function () {
echo "[finished]";
});

uv_queue_work($loop, function () use (&$completed) {
while (!$completed) {
echo "[queue1]";
$completed = true;
usleep(2);
}
}, function () {
echo "[finished]";
});

while (true) {
if ($completed) {
echo ' --finish-- ';
var_dump($completed);
uv_run($loop);
break;
}

uv_run($loop, UV::RUN_NOWAIT);
}
24 changes: 24 additions & 0 deletions examples/queue_channel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
$loop = \uv_default_loop();
[$read, $write] = \stream_socket_pair((\stripos(\PHP_OS, "win") === 0 ? \STREAM_PF_INET : \STREAM_PF_UNIX),
\STREAM_SOCK_STREAM,
\STREAM_IPPROTO_IP
);

$function = function () use ($write) {
echo "[queue1]";
\fwrite($write, "Thread 1\n");
\usleep(1);
};

\uv_queue_work($loop, $function, function () {
});

\uv_queue_work($loop, function () use ($read) {
echo "[queue2] ";
echo "Thread 2 Got " . \fgets($read);
}, function () {
});

\uv_run($loop);
\fclose($write);
2 changes: 1 addition & 1 deletion examples/readlink.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

uv_fs_readlink(uv_default_loop(), "linkPath", function($buffer){
uv_fs_readlink(uv_default_loop(), "linkPath", function ($buffer) {
var_dump($buffer);
});

Expand Down
53 changes: 53 additions & 0 deletions examples/signal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

$in = uv_pipe_init(uv_default_loop(), ('/' == \DIRECTORY_SEPARATOR));
$out = uv_pipe_init(uv_default_loop(), ('/' == \DIRECTORY_SEPARATOR));

$signal = uv_signal_init();

uv_signal_start($signal, function ($signal) {
print_r($signal);
echo PHP_EOL . 'The CTRL+C signal received, click the [X] to close the window.' . PHP_EOL;
uv_signal_stop($signal);
}, 2);

$signal = uv_signal_init();

uv_signal_start($signal, function ($signal) {
print_r($signal);
echo PHP_EOL . 'The SIGHUP signal received, the OS will close this session window!' . PHP_EOL;
}, 1);

echo "Hello, ";

$stdio = array();
$stdio[] = uv_stdio_new($in, UV::CREATE_PIPE | UV::READABLE_PIPE);
$stdio[] = uv_stdio_new($out, UV::CREATE_PIPE | UV::WRITABLE_PIPE);

$flags = 0;
$pid = uv_spawn(
uv_default_loop(),
"php",
array('-r', 'echo "World! " . PHP_EOL;'),
$stdio,
__DIR__,
[],
function ($process, $stat, $signal) {
if ($signal == 9) {
echo "The process was terminated with 'SIGKILL' or '9' signal!" . PHP_EOL;
}

uv_close($process, function () {
});
},
$flags
);

uv_read_start($out, function ($out, $nread, $buffer) {
echo $buffer;

uv_close($out, function () {
});
});

uv_run();
11 changes: 6 additions & 5 deletions examples/spawn.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

$in = uv_pipe_init(uv_default_loop(), true);
$out = uv_pipe_init(uv_default_loop(), true);
$in = uv_pipe_init(uv_default_loop(), ('/' == \DIRECTORY_SEPARATOR));
$out = uv_pipe_init(uv_default_loop(), ('/' == \DIRECTORY_SEPARATOR));

echo "HELLO ";

Expand All @@ -10,8 +10,8 @@
$stdio[] = uv_stdio_new($out, UV::CREATE_PIPE | UV::WRITABLE_PIPE);

$flags = 0;
uv_spawn(uv_default_loop(), "php", array('-r','var_dump($_ENV);'), $stdio, "/usr/bin/",
array("KEY"=>"hello"),
uv_spawn(uv_default_loop(), "php", array('-r','var_dump($_ENV);'), $stdio, "/usr/bin/",
array("KEY"=>"hello"),
function($process, $stat, $signal){
uv_close($process,function(){});

Expand All @@ -20,7 +20,8 @@ function($process, $stat, $signal){
uv_read_start($out, function($out, $buffer){
echo $buffer;

uv_close($out,function(){});
uv_close($out, function () {
});
});

uv_run();
6 changes: 3 additions & 3 deletions examples/spawn_fd.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$in = uv_pipe_init(uv_default_loop(), true);
$in = uv_pipe_init(uv_default_loop(), ('/' == \DIRECTORY_SEPARATOR));

echo "HELLO ";

Expand All @@ -11,8 +11,8 @@
$stdio[] = uv_stdio_new($fp, UV::INHERIT_FD | UV::WRITABLE_PIPE);

$flags = 0;
uv_spawn(uv_default_loop(), "php", ['-r', 'var_dump($_ENV);'], $stdio, "/usr/bin/",
["key" => "hello"],
uv_spawn(uv_default_loop(), "php", ['-r', 'var_dump($_ENV);'], $stdio, "/usr/bin/",
["key" => "hello"],
function($process, $stat, $signal){
uv_close($process,function(){});

Expand Down
Loading