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

SimonAngatia's avatar

PHP Fatal error: Allowed memory size of 104857600 bytes exhausted

I am getting this error every time I try running php artisan serve command in my project. I have tried increasing the memory limit in the php.ini file as many have suggested but it is still not working. The error seems to be coming from the guzzle package which makes requests. Before I got this error, I was making api calls to a certain API. I even tried restarting my computer but it didn't work. Please help me. This is the full error:

php artisan serve
PHP Fatal error:  Allowed memory size of 104857600 bytes exhausted (tried to allocate 20480 bytes) in C:\Users\user\Desk
top\content_creation\programming_projects\p1\vendor\guzzlehttp\guzzle\src\Client.php on line 256
PHP Fatal error:  Allowed memory size of 104857600 bytes exhausted (tried to allocate 32768 bytes) in C:\Users\user\Desk
top\content_creation\programming_projects\p1\vendor\symfony\error-handler\Error\FatalError.php on line 1
0 likes
12 replies
Sinnbeck's avatar

Perhaps you have a resursive call that keeps calling itself. What did you do just before getting this problem ?

SimonAngatia's avatar

@Sinnbeck This is the code I was executing:

public function updateLeagues($bets_api)
    {
        $sports = Sport::get();

            foreach ($sports as $sport) {
                $sport_id = $sport->sport_id;

                $leagues = $bets_api->soccerLeagues($sport_id);
   
                dd($leagues[0]);
                
            }
      
    }
SimonAngatia's avatar

@Sinnbeck That is the code I was trying to execute before I got that error for the first time in the terminal. I tried everything to solve it but it din't work. When I restarted my laptop and tried to run the laravel project again using the php artisan serve command, I was shocked that I was still getting the same error. That code is in a service that I call from a command that I created to execute the code every time I run it.

SimonAngatia's avatar

@Sinnbeck If I run php artisan serve in another project, it starts the server. However, if I run it in this particular project I am talking about, I get that error and it doesn't start the server.

Sinnbeck's avatar

@SimonAngatia Yeah you need to find out where in the code the problem is. You can start by making use it isnt in vendor. Delete the folder and run

composer install
SimonAngatia's avatar

@Sinnbeck When I run that, I get the same error

> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
PHP Fatal error:  Allowed memory size of 1610612736 bytes exhausted (tried to allocate 12288 bytes) in C:\Users\user\Desktop\content_creation\programming_projects\demobet\vendor\guzzlehttp\guzzle\src\Handler\Proxy.php on line 47
PHP Fatal error:  Allowed memory size of 1610612736 bytes exhausted (tried to allocate 8192 bytes) in C:\Users\user\Desktop\content_creation\programming_projects\demobet\vendor\symfony\error-handler\Error\FatalError.php on line 50
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255
Sinnbeck's avatar

@SimonAngatia Ok. See if you can figure it out. If not, I can perhaps take a quick look if you push to a branch

SimonAngatia's avatar

@Sinnbeck Hey, I have realized that the problem is in the Commands folder and specifically the commands files I had created. Could you help me realize the error in the files.

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Andonovn\LaravelBetsApi\BetsApi;
use App\Services\FetchOdds;


class FetchEventOdds extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'sb:fetch-event-odds';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Fetches event odds from soccer_events event_id';
    private $fetchOdds;
    public $betsApiIntance;
    public function __construct(BetsApi $betsapi, FetchOdds $fetchOdds)
    {
        parent::__construct();
        $this->fetchOdds = $fetchOdds;
        $this->betsApiIntance = $betsapi;
    }

    public function handle()
    {
        $this->fetchOdds->fetchOdds($this->betsApiIntance);
        $this->info("Sports data updated");
    }
}

Sinnbeck's avatar

@SimonAngatia be aware that that constructor is called on all commands. Maybe one of those two does stuff in its constructor

Inject into handle instead

Please or to participate in this conversation.