Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

luk's avatar
Level 1

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 65536 bytes)

i got this error when i run sever.php ,and i tray to change the memory size but the error is still here sever.php

<?php
require __DIR__ . '/vendor/autoload.php';
require 'core/Chat.php';
use Ratchet\Server\IoServer;
use MyApp\Chat;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;

$server = IoServer::factory(
            new HttpServer(
                new WsServer(
                    new Chat()
                )
            ),
          8087
         );$server->run();

chat.php

<?php
namespace MyApp;
require 'Chat.php';
use Ratchet\ConnectionInterface; 
use Ratchet\MessageComponentInterface;


class Chat implements MessageComponentInterface
 {  protected $clients;
    public $userObj, $data;

  public function __construct() {
      $this->clients = new \SplObjectStorage;
      $this->userObj = new \MyApp\User;
  } 

   public function onOpen(ConnectionInterface $conn)
  {
     // Store the new connection to send messages to later
     $this->clients->attach($conn);
     var_dump($this->userObj->userData('11'));
     echo "New connection! ({$conn->resourceId})\n";
  }  

  public function onMessage(ConnectionInterface $from, $msg) 
  {
      $numRecv = count($this->clients) - 1;
      echo sprintf('Connection %d sending message "%s" to %d other connection%s' . "\n",

        $from->resourceId, $msg, $numRecv, $numRecv ==  1 ? '' : 's');    
        foreach ($this->clients as $client) {
           if ($from !== $client) {
        //The sender is not the receiver, send to other clients
          $client->send($msg);
        }
      }
  }

    public function onClose(ConnectionInterface $conn)
  {
     // The connection is closed, remove from connection list
     $this->clients->detach($conn);
     echo "Connection {$conn->resourceId} has disconnected\n";
  }

    public function onError(ConnectionInterface $conn, \Exception $e)
  {
      echo "An error has occurred: {$e->getMessage()}\n";
      $conn->close();
  }
}

any one who can help me please?

0 likes
0 replies

Please or to participate in this conversation.