问题描述
我正在尝试从 http://socketo.me/docs/hello- 实现基本的聊天应用程序世界,但是我不断收到此错误.我试图移动文件,但没有成功,但我很确定我没有将文件放在正确的位置.我对 composer 和 websockets 以及 psr-0 完全陌生,我仍然有很多关于 PHP 的知识要学习.这是我的路径树和来源:
I am trying to implement the basic chat application from http://socketo.me/docs/hello-world, however I keep getting this error. I tried to move files around, but with no success, but I am quite sure that I don't put the files in the right place. I'm completly new to composer and websockets and psr-0 and I still have a lot to learn about PHP. Here are my path tree and my sources:
C:\wamp\www\
bin
chat-server.php
src
MyChat
Chat.php
vendor
{dependencies}+autoload.php
composer.json
composer.phar
composer.lock
Chat.php
<?php
namespace MyChat;
require dirname(__DIR__) . '\vendor\autoload.php';
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
class Chat implements MessageComponentInterface
{
protected $clients;
function __construct()
{
$this->clients=new \SplObjectStorage();
}
function onOpen(ConnectionInterface $conn)
{
$this->clients->attach($conn);
echo "New connection! ({$conn->resourceId})\n";
}
function onClose(ConnectionInterface $conn)
{
echo "Connection closed: {$conn->resourceId} \n";
$this->clients->detach($conn);
}
function onError(ConnectionInterface $conn, \Exception $e)
{
echo "An error has occured: {$e->getMessage()}. Closing connection... \n";
$conn->close();
}
function onMessage(ConnectionInterface $from, $msg)
{
$receivers=count($this->clients)-1;
foreach($this->clients as $client)
{
if($client!=$from)
{
$client->send($msg);
}
}
}
}
chat-server.php
<?php
require dirname(__DIR__) . '\vendor\autoload.php';
use Ratchet\Server\IoServer;
use MyChat\Chat;
$server= IoServer::factory (new Chat() ,8080,'0.0.0.0');//0.0.0.0 is default, means accept all connections
$server->run();
composer.json
{
"require": {
"cboden/Ratchet": "0.2.*"
},
"autoload": {
"psr-0": {
"MyChat": "src"
}
}
}
我的 php.exe 在 C:\wamp\bin\php\php5.4.12 中.我真的很感谢你的建议,我真的找不到我错在哪里.
My php.exe is in C:\wamp\bin\php\php5.4.12 . I would be really thankful for a suggestion, I can't really spot where am I mistaken.
推荐答案
这有点晚了,但看起来您正在使用 Composer,所以您可能需要运行该安装程序?
This is a little late but it looks like you are using composer, so you may need to run that installer?
在您的目录中尝试运行每一个,看看是否有帮助:
From your directory try running each of these and see if that helps:
./composer.phar install --dev
./composer.phar update
这篇关于类 &#39;MyChat\Chat&#39;在 C:\wamp\www\bin\chat-server.php 中找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!