与棘轮捆绑在一起的PHP ZMQ在Windows上不起作用,但在Linux上将起作用。当它在Linux上运行时,该消息将输出到服务器控制台。相同的脚本在Windows上不起作用。它正在运行,但未收到任何消息。
我已经用PHP 7.2安装了XAMPP。我已将以下文件复制到如下所示的方向。 (https://pecl.php.net/package/zmq/1.1.3/windows)使用线程安全版本。 x64和x86
DIR:C:\ xampp \ phplibzmq.dlllibzmq.pdb
DIR:C:\ xampp \ php \ extphp_zmq.dllphp_zmq.pdb
我已经重新启动apache并从命令行调用php,如下所示:php push-server.php
服务器运行,但是从浏览器访问“ post.php”时,回显“ Done”,但在控制台中从未收到任何消息。
我已禁用Windows防火墙,Windows UAC,以管理员身份运行命令提示符。
post.php
// This is our new stuff
$context = new ZMQContext();
$socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'PUSHER');
$socket->connect("tcp://localhost:5555");
$socket->send("Hello World");
echo 'Done!';
pusher.php
namespace MyApp;
use Ratchet\ConnectionInterface;
use Ratchet\Wamp\WampServerInterface;
class Pusher implements WampServerInterface {
public function onSubscribe(ConnectionInterface $conn, $topic) {
echo 'Subscribed'."\r\n".$topic;
}
public function onUnSubscribe(ConnectionInterface $conn, $topic) {
}
public function onOpen(ConnectionInterface $conn) {
}
public function onClose(ConnectionInterface $conn) {
}
public function onCall(ConnectionInterface $conn, $id, $topic, array $params) {
// In this application if clients send data it's because the user hacked around in console
$conn->callError($id, $topic, 'You are not allowed to make calls')->close();
}
public function onPublish(ConnectionInterface $conn, $topic, $event, array $exclude, array $eligible) {
// In this application if clients send data it's because the user hacked around in console
$conn->close();
}
public function onError(ConnectionInterface $conn, \Exception $e) {
}
}
push-server.php
require '../application/vendor/autoload.php';
require('pusher.php');
$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:5555'); // Binding to 127.0.0.1 means the only client that can connect is itself
$pull->on('message', function ($msg) {
echo 'Hello World!';
});
$pull->on('error', function ($e) {
echo $e->getMessage();
});
// Set up our WebSocket server for clients wanting real-time updates
$webSock = new React\Socket\Server('0.0.0.0:8080', $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();
``
The expected result is "Hello World!" in server console on Windows however nothing is ever shown.
The same script works on Centos 7 with the same version of PHP and ZMQ.
奇怪的是,它刚刚开始工作。我所做的就是禁用SSL。我很困惑。