Laravel 5 Outofmemory错误字符串调试MessageComponentInterface方法变量
在我的Laravel5.7应用程序中,我使用MessageComponentInterface作为聊天应用程序,其类如下Laravel 5 Outofmemory错误字符串调试MessageComponentInterface方法变量,laravel-5,socket.io,Laravel 5,Socket.io,在我的Laravel5.7应用程序中,我使用MessageComponentInterface作为聊天应用程序,其类如下 <?php namespace App\Classes\Socket; use App\Classes\Socket\Base\BaseSocket; use Ratchet\MessageComponentInterface; use Ratchet\ConnectionInterface; class ChatSocket extends BaseSocket
<?php
namespace App\Classes\Socket;
use App\Classes\Socket\Base\BaseSocket;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
class ChatSocket extends BaseSocket
{
protected $clients;
public function __construct()
{
$this->clients = new \SplObjectStorage;
}
public function onOpen(ConnectionInterface $conn) {
$this->clients->attach($conn);
echo '<pre>New Connection ::'.print_r($conn->resourceId,true).'</pre>';
}
public function onMessage(ConnectionInterface $from, $msg) {
$numRecv= count($this->clients)-1;
echo '<pre>onMessage $msg::' . print_r( $msg, true ) ;
// var_dump($from);
dump($from);
die("-1 XXZ000");
echo '<pre>onMessage $from::' . print_r( $from, true ) ;
...
并重新启动了我的服务器,但无论如何,我得到了内存不足的错误
使用这些方法:
memory_limit = 8048M
我在控制台中得到了无休止的输出,但我什么也抓不到
如何调试这些值
已更新#2
我试着以身作则
文章,但当我尝试使用方法运行它时:
echo '<pre>onMessage getNiceFileSize(memory_get_usage()) ::' . print_r( $this->getNiceFileSize(memory_get_usage()) , true ) ;
it shows :19241736 ~18 MiB
我得到一个错误:
Out of memory (allocated 1623195648) (tried to allocate 1600131072 bytes)
在上述文章中有一条评论:
(您必须解密cookie才能获得Laravel 5中的会话id):
我搜索这个我找到了这个
在web请求上下文中,cookies通常会自动加密并
由加密cookies中间件解密。所以最简单的选择是
只需启用此中间件(默认情况下在
拉拉维尔)
在我的app/Http/Kernel.php中,有一行是加密cookie
public function onMessage(ConnectionInterface $from, $msg) {
// start the session when the user send a message
// (refreshing it to be sure that we have access to the current state of the session)
$from->session->start();
// do what you wants with the session
// for example you can test if the user is auth and get his id back like this:
$idUser = $from->session->get(Auth::getName());
if (!isset($idUser)) {
echo "the user is not logged via an http session";
} else {
$currentUser = User::find($idUser);
}
// or you can save data to the session
$from->session->put('foo', 'bar');
// ...
// and at the end. save the session state to the store
$from->session->save();
}
但这是web应用程序,但我运行的是控制台应用程序。
我必须将EncryptCookie添加到app/Http/Kernel.php中的其他组中,这是错误的原因吗?
或者为什么会出错
也
在里面file:///etc/php/7.2/cli/php.ini
我修改了
并重新启动了apache
我还尝试检查脚本中有多少内存:
我试着计算,得到了1.51Gib和1.49Gib的值
- 1) 为什么内存使用返回这么小的值2)为什么转储得到 1.5吉布?这是一个很大的价值3)有什么办法处理它吗?4) Auth::id()不返回任何内容,据我所知,它不会有帮助, as消息可以由其他登录用户发送,但当前不能发送 记录的
Undefined property: Ratchet\Server\IoConnection::$session
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
memory_limit = 8048M
echo '<pre>onMessage getNiceFileSize(memory_get_usage()) ::' . print_r( $this->getNiceFileSize(memory_get_usage()) , true ) ;
it shows :19241736 ~18 MiB
Out of memory (allocated 1623195648) (tried to allocate 1600131072 bytes)
public function onMessage(ConnectionInterface $from, $msg) {
// start the session when the user send a message
// (refreshing it to be sure that we have access to the current state of the session)
$from->session->start();
// do what you wants with the session
// for example you can test if the user is auth and get his id back like this:
$idUser = $from->session->get(Auth::getName());
if (!isset($idUser)) {
echo "the user is not logged via an http session";
} else {
$currentUser = User::find($idUser);
}
// or you can save data to the session
$from->session->put('foo', 'bar');
// ...
// and at the end. save the session state to the store
$from->session->save();
}