��php-fpm��apache��ʹ��swoole

swoole��չ��swoole_serverֻ����cliģʽ��ʹ�ã�������ģʽ�»��׳��������� ��swoole_client��swoole_event�ǿ�������php-fpm��apache+mod_php5�еġ�

��Ҫע�����ʹ��swoole_client�첽��swoole_event�������������յ����������һ��Ҫִ��$client->close()��swoole_event_del��swoole_event_exit������swoole�޷���֪ʲôʱ��Ҫֹͣepoll wait��

ͬ��swoole_client

<?php
$client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC); //ͬ������
$client->connect('127.0.0.1', 9501) or die("connect failed\n");

$client->send(str_repeat("A", 600));
$data = $client->recv(700, 0) or die("recv failed\n);;
echo "recv: ",$data,"\n";

�첽swoole_client

<?php
$client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC); //�첽������

$client->on("connect", function(swoole_client $cli) {
    $cli->send("GET / HTTP/1.1\r\n\r\n");
});

$client->on("receive", function(swoole_client $cli, $data){
    echo "Received: $data";
    $cli->close();
});

$client->on("error", function(swoole_client $cli){
    exit("error\n");
});

$client->on("close", function(swoole_client $cli){
    echo "Connection close";
});

$client->connect('127.0.0.1', 9501, 0.5);

echo "connect to 127.0.0.1:9501";
//for PHP5.3-
//swoole_event_wait();