How to solve a timeout error in Laravel 5

后端 未结 13 2070
说谎
说谎 2020-11-30 08:43

I have the following set up:

In routes I have:

Route::get(\'articles\', \'ArticlesController@index\');

The index method in the controller is simply:<

相关标签:
13条回答
  • 2020-11-30 08:48

    Add above query

    ini_set("memory_limit", "10056M");

    0 讨论(0)
  • 2020-11-30 08:52

    In Laravel:

    Add set_time_limit(0) line on top of query.

    set_time_limit(0);
    
    $users = App\User::all();
    

    It helps you in different large queries but you should need to improve query optimise.

    0 讨论(0)
  • 2020-11-30 08:54

    set time limit in __construct method or you can set in your index controller also where you want to have large time limit.

    public function __construct()
    {
        set_time_limit(8000000);
    }
    
    0 讨论(0)
  • 2020-11-30 08:55

    it's a pure PHP setting. The alternative is to increase the execution time limit only for specific php scripts, by inserting on top of that php file, the following:

    ini_set('max_execution_time', 180); //3 minutes
    
    0 讨论(0)
  • 2020-11-30 08:56

    try

    ini_set('max_execution_time', $time);
    $articles = Article::all();
    

    where $time is in seconds, set it to 0 for no time. make sure to make it 60 back after your function finish

    0 讨论(0)
  • 2020-11-30 08:56

    If you are hosting your Laravel app on Heroku, you can create custom_php.ini in the root of your project and simply add max_execution_time = 60

    0 讨论(0)
提交回复
热议问题