错误使用PHP的WebSocket和WAMP服务器 [英] Error with PHP Websocket and Wamp Server

查看:639
本文介绍了错误使用PHP的WebSocket和WAMP服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很新的这个的WebSockets的,我试图连接此的WebSocket:的 phpwebsocket 与WAMP的服务器,首先,在我的httpd.conf我写听9300的,如果我去为localhost:9300它的作品的权利,但是当我去安慰和写:

I'm really new about this of Websockets, i'm trying to connect this websocket: phpwebsocket with WAMP server, first, in my httpd.conf I wrote listen 9300, and if i go to localhost:9300 it works right, but when I go to console and write:

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

我得到这个错误:

I got this error:

下面是server.php的code:

Here's the code of 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输出

And also, the output of php -me

推荐答案

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

In WAMP Server, if you are running from a command line you are using PHP CLI.

该PHP CLI使用不同的php.ini文件,当PHP在Apache运行使用。

The PHP CLI uses a different php.ini file to that used when php runs in apache.

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

和取消对php_sockets延长线和运行PHP CLI时可能需要的任何其他扩展名。

and uncomment the php_sockets extension line and any other extensions you may need when running PHP CLI.

这篇关于错误使用PHP的WebSocket和WAMP服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆