08-06-2023, 05:08 PM
This is a complex issue to work with. That happens when you have a huge data to handle with or working with a slow API, slow/weak server or else, so you have to tune up several things:
- webserver (Nginx for sure)
- PHP-CLI
- Laravel
- [Supervisor][1]
You need to test execution timeout by yourself. In this case let's make `10000` (seconds)
Nginx config
------------
[proxy_read_timeout][2] directive - you can increase this value for a needle timeout one in your nginx config.
`nano /etc/nginx/sites-available/mysite.com.conf`
`proxy_read_timeout 10000`
PHP-CLI config
--------------
[memory_limit][3] directive that works with RAM. You can turn off all limits for PHP-CLI scripts with value of `-1`
[max_execution_time][4] directive, time in seconds allowed for script execute. Optional, but you can test up increasing of this value.
`nano /etc/php/8.1/cli/php.ini`
`memory_limit=-1`
`max_execution_time=10000`
Laravel
----------
[Timeouts][5]. Increase timeout time of your [Queue][6] [Job/Task][7]. Also you can turn off [failing on timeout][8]
<?php
namespace App\Jobs;
class MyJobTask implements ShouldQueue
{
/**
* The number of seconds the job can run before timing out.
*
* @var int
*/
public $timeout = 10000;
/**
* Indicate if the job should be marked as failed on timeout.
*
* @var bool
*/
public $failOnTimeout = false;
}
Supervisor
----------
Supervisor is a service to control queue processes on a server side. [Install and tune up supervisor][1] config for your Laravel project. But don't forget to provide `--timeout` option with a `command` in your config.
`command=/usr/bin/php /var/www/app.com/artisan queue:work database --timeout=10000`
[1]:
- webserver (Nginx for sure)
- PHP-CLI
- Laravel
- [Supervisor][1]
You need to test execution timeout by yourself. In this case let's make `10000` (seconds)
Nginx config
------------
[proxy_read_timeout][2] directive - you can increase this value for a needle timeout one in your nginx config.
`nano /etc/nginx/sites-available/mysite.com.conf`
`proxy_read_timeout 10000`
PHP-CLI config
--------------
[memory_limit][3] directive that works with RAM. You can turn off all limits for PHP-CLI scripts with value of `-1`
[max_execution_time][4] directive, time in seconds allowed for script execute. Optional, but you can test up increasing of this value.
`nano /etc/php/8.1/cli/php.ini`
`memory_limit=-1`
`max_execution_time=10000`
Laravel
----------
[Timeouts][5]. Increase timeout time of your [Queue][6] [Job/Task][7]. Also you can turn off [failing on timeout][8]
<?php
namespace App\Jobs;
class MyJobTask implements ShouldQueue
{
/**
* The number of seconds the job can run before timing out.
*
* @var int
*/
public $timeout = 10000;
/**
* Indicate if the job should be marked as failed on timeout.
*
* @var bool
*/
public $failOnTimeout = false;
}
Supervisor
----------
Supervisor is a service to control queue processes on a server side. [Install and tune up supervisor][1] config for your Laravel project. But don't forget to provide `--timeout` option with a `command` in your config.
`command=/usr/bin/php /var/www/app.com/artisan queue:work database --timeout=10000`
[1]:
[To see links please register here]
[2]:[To see links please register here]
[3]:[To see links please register here]
[4]:[To see links please register here]
[5]:[To see links please register here]
[6]:[To see links please register here]
[7]:[To see links please register here]
[8]:[To see links please register here]