Whenever I try to call an event in Laravel 8, a memory leak happens and it crashes the server.
Here is the event:
class NewOrderEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $order_id;
public $user_id;
public function __construct($order_id, $user_id)
{
$this->order_id = $order_id;
$this->user_id = $user_id;
}
public function broadcastOn()
{
Log::info('Memory usage broadcastOn: '. memory_get_peak_usage());
return [new Channel('orders-' . $this->user_id)];
}
public function broadcastWith()
{
Log::info('Memory usage broadcastWith: '. memory_get_peak_usage());
return [
'id' => $this->order_id,
];
}
public function broadcastAs()
{
return ('orders');
}
}
And the logs:
local.INFO: Memory usage broadcastOn: 5787040
local.INFO: Memory usage broadcastWith: 5787312
How can I reduce the memory usage of the event?
I’ve tried to free $this->user_id but it didn’t work
ERROR:
Request Timeout
This request takes too long to process, it is timed out by the server. If it should not be timed out, please contact the administrator of this website to increase the ‘Connection Timeout’.