PHPページがソケットを介して正常に接続されている別のTCPサーバーでイベントが発生したときに、 Webサーバーがphpページを介して通知するようにします。このイベントは、TCPサーバーがWebサーバーなどにメッセージを送信したいようなものです。これを実現する方法や、その方法に関するリファレンスはありますか?
2181 次
1 に答える
2
もちろん:
$fp = fsockopen("tcp://example.com", 8888) OR die("could not connect");
while (!feof($fp)) {
$pc = fread($handle, 8192);
if ($pc === false || strlen($pc) == 0)
break;
//a new packet has arrived
//you should collect the read in a variable and wait
//for another packet until you know the message is complete
//(depends on the protocol)
collect_in_result($pc);
if (message_is_complete()) {
if (check_event()) {
//take action
}
}
}
于 2010-06-14T10:11:53.947 に答える