2013-07-17 111 views
3

我對這個Websockets真的很陌生,我試圖用WAMP服務器連接這個websocket:phpwebsocket,首先在我的httpd.conf中,我寫了聽9300,如果我去爲localhost:9300它的作品的權利,但是當我去安慰和寫:PHP Websocket和Wamp服務器的錯誤

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

+0

也許你還沒有安裝php5_socket擴展插槽啓用。試試這個http://www.php.net/manual/en/sockets.installation.php –

+0

我有這樣的行: extension = php_sockets.dll沒有; – Darkness

+1

在命令行輸入「php -me」。它在輸出中是否有「套接字」? –

回答

6

在WAMP Server中,如果您正在使用命令行運行PHP CLI,

PHP CLI使用與php在apache中運行時所用的不同的php.ini文件。

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

取消註釋php_sockets擴展行以及運行PHP CLI時可能需要的任何其他擴展。

+0

好吧,用edit.exe,我看到我有;在php_sockets中,我不知道爲什麼...但記事本我沒有php_sockets;無論如何,非常感謝你! – Darkness

+0

感謝你 - 只是想在我的特定配置(UniServerZ)中添加它是'php-cli.ini'我將php_development.ini文件中的'extension = php_sockets.dll'行復制到'php-cli.ini '它的工作。 – user1274820

0

我在我的網站上運行,主辦合夥人說你不能在共享主機u需要購買VPS服務器託管任何solution.on本地主機它工作正常property in dubai