php - PHP Websocket 和 Wamp 服务器出错

标签 php apache websocket wamp phpwebsocket

我对这个 Websockets 很陌生,我正在尝试连接这个 websocket:phpwebsocket使用 WAMP 服务器,首先,在我的 httpd.conf 中,我写了 listen 9300,如果我转到 localhost:9300,它会正常工作,但是当我转到控制台并写入时:

 php -q C:\wamp\www\demos\server.php

我遇到了这个错误:

error

这是 server.php 的代码:

<?php
set_time_limit(0);
require 'class.PHPWebSocket.php';
function wsOnMessage($clientID, $message, $messageLength, $binary) {
    global $Server;
    $ip = long2ip( $Server->wsClients[$clientID][6] );
    if ($messageLength == 0) {
        $Server->wsClose($clientID);
        return;
    }

    if ( sizeof($Server->wsClients) == 1 )
        $Server->wsSend($clientID, "There isn't anyone else in the room, but I'll still listen to you. --Your Trusty Server");
    else
        foreach ( $Server->wsClients as $id => $client )
            if ( $id != $clientID )
                $Server->wsSend($id, "Visitor $clientID ($ip) said \"$message\"");
}
function wsOnOpen($clientID)
{
    global $Server;
    $ip = long2ip( $Server->wsClients[$clientID][6] );

    $Server->log( "$ip ($clientID) has connected." );

    foreach ( $Server->wsClients as $id => $client )
        if ( $id != $clientID )
            $Server->wsSend($id, "Visitor $clientID ($ip) has joined the room.");
}
function wsOnClose($clientID, $status) {
    global $Server;
    $ip = long2ip( $Server->wsClients[$clientID][6] );

    $Server->log( "$ip ($clientID) has disconnected." );
    foreach ( $Server->wsClients as $id => $client )
        $Server->wsSend($id, "Visitor $clientID ($ip) has left the room.");
}
$Server = new PHPWebSocket();
$Server->bind('message', 'wsOnMessage');
$Server->bind('open', 'wsOnOpen');
$Server->bind('close', 'wsOnClose');
$Server->wsStartServer('localhost', 9300);

?>

谢谢。

哦,还有我的扩展:

;extension=php_bz2.dll
extension=php_curl.dll
;extension=php_dba.dll
extension=php_mbstring.dll
;extension=php_exif.dll
;extension=php_fileinfo.dll
extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_intl.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
;extension=php_ming.dll
;extension=php_mssql.dll
extension=php_mysql.dll
extension=php_mysqli.dll
;extension=php_oci8.dll      
;extension=php_oci8_11g.dll 
extension=php_openssl.dll
;extension=php_pdo_firebird.dll
;extension=php_pdo_mssql.dll
extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
;extension=php_phar.dll
;extension=php_pspell.dll
;extension=php_shmop.dll
;extension=php_snmp.dll
;extension=php_soap.dll
extension=php_sockets.dll
;extension=php_sqlite.dll
;extension=php_sqlite3.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
;extension=php_xsl.dll
;extension=php_zip.dll

还有,php -me 的输出

PHP -me

最佳答案

在 WAMP 服务器中,如果您从命令行运行,则您使用的是 PHP CLI。

PHP CLI 使用与 php 在 apache 中运行时不同的 php.ini 文件。

Edit c:\wamp\bin\php\php5.x.y\php.ini

并取消注释 php_sockets 扩展行和运行 PHP CLI 时可能需要的任何其他扩展。

关于php - PHP Websocket 和 Wamp 服务器出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17705630/

相关文章:

phpMyAdmin 访问被拒绝

apache - OpenMEAP 通过 OpenShift 社区托管在 Apache Tomcat 服务器上

javascript - 为什么我们在定义 WebSocket 对象的委托(delegate)后无法手动打开它的连接?

https - IE10 websocket allowInsecureFromHttps

javascript - 使用 PHP 设置焦点并选择错误的内容元素

php - 将 JavaScript 变量发送到 PHP 变量

php - 如何与相关实体独立设置 Symfony2 Bundles

regex - URL 编码文本与 htaccess QUERY_STRING 不匹配

apache - Tomcat 服务 URLs mod_proxy 和 apache 错误

c++ - QWebSocket "Unknown Error"