如何在PHP中处理套接字
我正在使用PHP在web服务器上创建套接字 目前我有A-服务器,B-一台在数据库上寻找更改的设备(在A中)和C-一台在数据库上进行更改的设备(在A中),并发出如何在PHP中处理套接字,php,sockets,ratchet,Php,Sockets,Ratchet,我正在使用PHP在web服务器上创建套接字 目前我有A-服务器,B-一台在数据库上寻找更改的设备(在A中)和C-一台在数据库上进行更改的设备(在A中),并发出curl请求 当前当C进行更改时,我将更改存储在A上的数据库中。当B通过套接字每秒检查A数据库中是否有项目时,向A发送请求,其中A返回响应。这是Bs资源的腰围。我需要一种方法来确定C何时更改套接字以更新B 这是套接字的代码: <?php namespace Notify; use Ratchet\MessageComponentInt
curl
请求
当前当C进行更改时,我将更改存储在A上的数据库中。当B通过套接字每秒检查A数据库中是否有项目时,向A发送请求,其中A返回响应。这是Bs资源的腰围。我需要一种方法来确定C何时更改套接字以更新B
这是套接字的代码:
<?php
namespace Notify;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
require "/NAS/notify/db.php";
class Note implements MessageComponentInterface {
protected $clients;
public function __construct() {
$this->clients = new \SplObjectStorage;
}
public function onOpen(ConnectionInterface $conn) {
$this->clients->attach($conn);
}
public function onMessage(ConnectionInterface $from, $msg) {
$stack = array();
foreach ($this->clients as $client) {
if ($from === $client) { //current client only
$query = getNotifications($msg);
if($query){
while($row = mysqli_fetch_assoc($query)){
array_push($stack, $row);
deleteNotification($row['id'], $msg);
}
$client->send(json_encode($stack));
}
}
}
}
public function onClose(ConnectionInterface $conn) {
$this->clients->detach($conn);
}
public function onError(ConnectionInterface $conn, \Exception $e) {
$conn->close();
}
}
考虑使用发布-订阅模式,其中查找对象“X”更新的客户端订阅主题,然后让服务器发布该主题。Ratchet可以使用WAMPv1:处理此问题,也可以使用构建在Ratchet之上的WAMPv1:解决此问题。谢谢!你有更好的使用wamp的例子吗?关于我的问题,我不明白有哪些文件。