ext-uv/examples/pipe_bind_connect.php

32 lines
801 B
PHP
Raw Normal View History

2012-06-02 14:45:43 +02:00
<?php
2020-02-15 22:36:03 +01:00
if (stripos(PHP_OS, "WIN") == 0) {
define("PIPE_PATH", "\\\\.\\pipe\\MyPipeName");
} else {
define("PIPE_PATH", dirname(__FILE__) . "/pipe_test.sock");
@unlink(PIPE_PATH);
}
2012-07-03 01:01:32 +02:00
$a = uv_pipe_init(uv_default_loop(), 0);
$ret = uv_pipe_bind($a,PIPE_PATH);
2020-02-15 22:36:03 +01:00
uv_listen($a, 8192, function($stream) {
2012-07-03 01:01:32 +02:00
$pipe = uv_pipe_init(uv_default_loop(),0);
uv_accept($stream,$pipe);
2020-02-15 22:36:03 +01:00
uv_read_start($pipe,function($pipe, $buffer) use ($stream) {
2012-07-03 01:01:32 +02:00
echo $buffer;
2012-06-02 14:45:43 +02:00
uv_read_stop($pipe);
2012-07-03 01:01:32 +02:00
uv_close($stream, function(){
@unlink(PIPE_PATH);
});
2012-06-02 14:45:43 +02:00
});
});
2012-07-03 01:01:32 +02:00
$b = uv_pipe_init(uv_default_loop(), 0);
2020-02-15 22:36:03 +01:00
uv_pipe_connect($b, PIPE_PATH, function($pipe, $status) {
uv_write($pipe, "Hello", function($stream, $status) {
2012-07-03 01:01:32 +02:00
uv_close($stream);
2012-06-02 14:45:43 +02:00
});
});
uv_run();
2012-07-10 16:44:54 +02:00
exit;