
2016-12-20 | ©★ 發布者:梁國(guó)芳 ★×$; | &nb ×∞♦sp; 查看(kàn):3320 φ次
phpSwoole可(kě)以廣泛應用(yòng)于£✘互聯網、移動通(tōng)信、企業(yè)軟件(jiàn)、雲計(jì< )算(suàn)、網絡遊戲、物(wù)聯網(IOT)、車(chē)聯φ∞ 網、智能(néng)家(jiā)居等領域。 使用(yòσ©βng)PHP+Swoole作(zuò)為(wèi)網絡通(tōng¶★∑₹)信框架,可(kě)以使企業(yè)IT研發團隊的(de)效率大(dà)大&δ(dà)提升,更加專注于開(kāi)發創新産品。
注意事(shì)項:
1、server.php中的(de)ip地(dì)址必須是(shì)外(wà♥¶i)網可(kě)訪問(wèn)地(dì)址 12÷€3.57.232.99,不(bù)能(néng)為(wèi)local<host
1、安裝
# wget https://g€↑ithub.com/swoole/swoole-src/arc₽"→hive/swoole-1.7.6-stable.t✘β♣ar.gz
# tar zxvf swoole-1.7.6-stable.tar.gz
# cd swoole-1.7.6-stab↕☆le
/www/wdlinux/php/bin/p↑&hpize
# make && ±≥δmake install
提示:
Build complete.
Don't forget to run 'make tesλ✔t'.
Installing shared extensions€: /usr/>×lib64/php/modules/
說(shuō)明(míng)安裝成功
2、php加載swoole擴展
extension=/www/wdlinux/ap₽♠₽ache_php-5.6.21/lib/php/extensions/no-d •ebug-non-zts-20131226/swool ∑₹e.so
3、重啓服務
4、測試,查看(kàn)phpinfo信息,如(rú)下(xià)圖所示:
5、代碼測試
server.php代碼:
$serv = new swoole_server("123.•ε57.232.99", 55152);
$serv->on('connect',α∏ function ($serv, $fγ &d){
echo "Client:C•↕ ±onnect.\n";
});
$serv->on('receive', functio≈♦n ($serv, $fd, $from_id, $data) {
$serv->send($fd, 'Swoole: '.$data);
});
$serv->on('close', function λ"($serv, $fd) {
echo "Client: ★↑≈Close.\n";
});
$serv->start();
?>
client.php代碼
$client = new swoole_client(SWOOLE_SO ∏↑>CK_TCP);
if (!$client->connect('123.57.232.99', 5γ£5152, -1))
{
exit("connect failed. Error: {$client->errCλ₹↑ode}\n");
}
$client->send("h↕≠♦ello world\n");
echo $client->recv();
$client->close();
?>
首先啓動服務:
[root@iZ25l6q4losZ swoole]#β↓∑γ /www/wdlinux/php/bin/php server.php
Client:Connect.
然後Linux終端 telnet測試
# telnet 123.57.232.99 55152
Trying 123.57.232.99...
Connected to 123.57.232.99.
Escape character is '^]÷↑'.
rr
Swoole: rr
測試
Swoole: 測試

