Unable to connect to DB when executing laravel command in Docker environment

Asked 2 years ago, Updated 2 years ago, 368 views

The Ravel app is working properly in docker environment.

docker exec-it app bash

into the container, and just under the laravel project,

phpartisan command:test_command

When you run the and commands,

Within /app/Console/Commands/TestCommand,
When the model reads DB data, no errors occur. The process will end.

phpartisan migrate —Status connects to the DB and prints a list of migration information.


When the following actions occur within /app/Console/Commands/TestCommand: Test1 is printed, but test2 is not printed, there is no error log, and it appears that the process is finished at Company::all();

public function handle()
    {

    print "test1";
    
    $company=Company::all();

    print "test2";

    exit;
        }

If you know how to solve this problem, please let me know.

Instead of command, the web browsing side connects to DB without any problems, and the app is running

docker laravel

2022-09-30 22:05

1 Answers

Self-resolved.

Company::all(); has a lot of data in the companies table
The processing seemed to be slow due to lack of memory or something.

Company::chunk(100, function($companys){
        foreach($company as$company){
        print$company->id;
        }
    });

It worked when I retrieved it with chunk as shown in .


2022-09-30 22:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.