xref: /php-uv/examples/pipe_bind_connect.php (revision 99312394)
1<?php
2if (stripos(PHP_OS, "WIN") == 0) {
3	define("PIPE_PATH", "\\\\.\\pipe\\MyPipeName");
4} else {
5	define("PIPE_PATH", dirname(__FILE__) . "/pipe_test.sock");
6	@unlink(PIPE_PATH);
7}
8$a = uv_pipe_init(uv_default_loop(), 0);
9$ret = uv_pipe_bind($a,PIPE_PATH);
10
11uv_listen($a, 8192, function($stream) {
12    $pipe = uv_pipe_init(uv_default_loop(),0);
13    uv_accept($stream,$pipe);
14    uv_read_start($pipe,function($pipe, $buffer) use ($stream) {
15        echo $buffer;
16        uv_read_stop($pipe);
17        uv_close($stream, function(){
18            @unlink(PIPE_PATH);
19        });
20    });
21});
22
23$b = uv_pipe_init(uv_default_loop(), 0);
24uv_pipe_connect($b, PIPE_PATH, function($pipe, $status) {
25    uv_write($pipe, "Hello", function($stream, $status) {
26        uv_close($stream);
27    });
28});
29
30uv_run();
31exit;
32