PHP React\ZMQ\Context';在';方法不开火
我正在尝试使用php实现一个web套接字服务器 我已经按照指示去做了。但我无法将更改推送到客户端。我知道问题是“PHP React\ZMQ\Context';在';方法不开火,php,websocket,zeromq,ratchet,Php,Websocket,Zeromq,Ratchet,我正在尝试使用php实现一个web套接字服务器 我已经按照指示去做了。但我无法将更改推送到客户端。我知道问题是“React\ZMQ\Context”,它不会对任何事件做出反应 正如我所预料的,该组件应该对打开、关闭、消息和错误事件做出反应。这是我的密码: $loop = React\EventLoop\Factory::create(); $pusher = new MyApp\Pusher; // Listen for the web server to make a ZeroMQ pu
React\ZMQ\Context
”,它不会对任何事件做出反应
正如我所预料的,该组件应该对打开
、关闭
、消息
和错误
事件做出反应。这是我的密码:
$loop = React\EventLoop\Factory::create();
$pusher = new MyApp\Pusher;
// Listen for the web server to make a ZeroMQ push after an ajax request
$context = new React\ZMQ\Context( $loop );
$pull = $context->getSocket( ZMQ::SOCKET_PULL );
$pull->bind( 'tcp://127.0.0.1:9021' ); // Binding to 127.0.0.1 means the only client that can connect is itself
$pull->on( 'open', function( $msg ){ echo "open"; } );
$pull->on( 'close', function( $msg ){ echo "close"; } );
$pull->on( 'message', function( $msg ){ echo "message"; } );
$pull->on( 'error', function( $msg ){ echo "error"; } );
// Set up our WebSocket server for clients wanting real-time updates
$webSock = new React\Socket\Server( '0.0.0.0:8090', $loop ); // Binding to 0.0.0.0 means remotes can connect
$webServer = new Ratchet\Server\IoServer(
new Ratchet\Http\HttpServer(
new Ratchet\WebSocket\WsServer(
new Ratchet\Wamp\WampServer(
$pusher
)
)
),
$webSock
);
$loop->run();
谢谢。除非您同时修改ZeroMQ基础结构设置的
推送
-端,否则此操作将无效:
<?php
// post.php ???
// This all was here before ;)
$entryData = array(
'category' => $_POST['category']
, 'title' => $_POST['title']
, 'article' => $_POST['article']
, 'when' => time()
);
$pdo->prepare( "INSERT INTO blogs (title, article, category, published) VALUES (?, ?, ?, ?)" )
->execute( $entryData['title'], $entryData['article'], $entryData['category'], $entryData['when'] );
// This is our new stuff
$context = new ZMQContext();
$socket = $context->getSocket( ZMQ::SOCKET_PUSH, 'my pusher' );
$socket->connect( "tcp://localhost:5555" );
// ^^^^__________ MUST BECOME 9021 after your mod-s
$socket->send( json_encode( $entryData ) );
我已经在我的项目中使用了这个部分。此外,通过监视打开的端口,我了解到端口5555在我的系统上已打开。但是当我在这个端口上发送数据时,它没有任何反应。请尝试python-[PULL]-tester和python-[PUSH]-tester,首先测试整个测试路径。接下来,使用python-[PULL]-测试仪和php-[PUSH]-测试仪测试本机ZeroMQ操作,如果没有接收,php发送者将受到指责,如果接收,请尝试python-[PUSH]-测试仪,如果没有在php接收器中接收,您就到了现场。
import zmq
aClk = zmq.Stopwatch()
aContext = zmq.Context()
aTarget = "tcp://127.0.0.1:9021" # <- ADJUST TO PULL-er side transport-class endpoint
aPushToProveZMQ_RTO = aContext.Socket( zmq.PUSH )
aPushToProveZMQ_RTO.setsockopt( zmq.LINGER, 0 )
aPushToProveZMQ_RTO.connect( aTarget )
aClk.start()
try:
print( "INF: infinite loop, sending messages [[[ Use Ctrl+C to break ]]]" )
while True:
aPushToProveZMQ_RTO.send( "aLoop RTT::({0:}[us])".format( aClk.stop() ) )
pass; aClk.start()
except:
pass
finally:
aPushToProveZMQ_RTO.close()
aContext.term()
print( "INF: a gracefull exit" )