【问题标题】:Error with PHP Websocket and Wamp ServerPHP Websocket 和 Wamp 服务器出错
【发布时间】:2013-07-16 08:25:21
【问题描述】:

我对 Websockets 真的很陌生,我正在尝试将这个 websocket:phpwebsocket 与 WAMP 服务器连接起来,首先,在我的 httpd.conf 中我写了 listen 9300,如果我去 localhost:9300 它工作正常,但是当我去控制台写:

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

我收到了这个错误:

这是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 的输出

【问题讨论】:

  • 可能你没有安装php5_socket扩展。试试这个php.net/manual/en/sockets.installation.php
  • 我有这样一行:extension=php_sockets.dll 没有 ;
  • 在命令行中输入“php -me”。输出中是否有“sockets”?
  • 不,我没有 D:

标签: php apache websocket wamp phpwebsocket


【解决方案1】:

我在我的网站上运行,托管合作伙伴说你不能在共享主机上启用套接字你需要购买托管任何解决方案的 vps 服务器。在本地主机上它工作正常property in dubai

【讨论】:

    【解决方案2】:

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

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

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

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

    【讨论】:

    • 好的,用edit.exe我看到我有;在 php_sockets 中,我不知道为什么......但是使用记事本我没有 php_sockets ;不管怎样,非常感谢!!!
    • 谢谢你 - 只是想在我的特定配置 (UniServerZ) 中添加它是 php-cli.ini 我将行 extension=php_sockets.dll 从 php_development.ini 文件复制到 php-cli.ini 并且它工作。
    【解决方案3】:

    你必须安装 php_socket 扩展。 http://php.net/manual/en/install.windows.extensions.php 此链接包含有关它的所有信息。

    【讨论】:

      猜你喜欢
      • 2017-07-17
      • 2011-07-12
      • 2013-05-28
      • 1970-01-01
      • 2012-02-22
      • 2018-09-19
      • 1970-01-01
      • 2018-07-07
      • 1970-01-01
      相关资源
      最近更新 更多