Home > Article > PHP Framework > About thinkphp-queue problem solving
The following tutorial column will introduce to you how to solve the thinkphp-queue problem. I hope it will be helpful to friends who need it! Used version: TP5.1, thinkphp-queue 2.0
mysql timeout disconnection problem
Configuration file
database.phpConfigure disconnection and reconnection:
// 是否需要断线重连 'break_reconnect' => true, // 断线标识字符串 'break_match_str' => ['2006'],
After configuration, although another configuration will appear in the log An error is reported: PDO::prepare(): send of 60 bytes failed with errno=32 Broken pipe, but it does not affect the program running results. Because after disconnection and reconnection, the program will throw an error: <pre class="brush:php;toolbar:false">...} catch (\PDOException $e) {
if ($this->isBreak($e)) {
return $this->close()->query($sql, $bind, $master, $pdo);
}
throw new PDOException($e, $this->config, $this->getLastsql());} catch (\Throwable $e) {
if ($this->isBreak($e)) {
return $this->close()->query($sql, $bind, $master, $pdo);
}
throw $e;} catch (\Exception $e) {
if ($this->isBreak($e)) {
return $this->close()->query($sql, $bind, $master, $pdo);
}
throw $e;}</pre>
How to monitor the process in the docker environment
2. Run a new container to run queue tasks (no supervisor, container It is a daemon itself)
3. Run the queue task directly in the existing php container (use the –daemon option on the command line)
Method 1 supervisor reference configuration (put in /etc/supervisor/ conf.d, the file is named {file-name}.conf):
[program:my_queue_name]process_name=%(program_name)s_%(process_num)02d command=php /path/to/think queue:work --queue=your-queue-name --sleep=3 --daemon autostart=trueautorestart=truenumprocs=1user=root stopasgroup=truekillasgroup=trueredirect_stderr=truestdout_logfile=/path/to/your-queue.log
Method 2 Open a new mirror reference configuration (add services in docker-compose.yml):
php-queue: container_name: queue image: docker_php-fpm73 restart: always command: php path/to/think queue:work --sleep=3 volumes: - ../project:/var/www/html - ./conf/php:/usr/local/etc/php - ./conf/php/conf.d:/usr/local/etc/php/conf.d - ./conf/supervisor:/etc/supervisor/conf.d networks: - mysql - nginx
Method three is a bit hacky. In order not to change the online environment greatly, method three is finally used (operating on the host machine).
Start up:
docker exec -i php7 php /path/to/think queue:work --queue=my-queue-name --sleep=3 --daemonRestart: docker exec -i php7 php /path/to/think queue:restart
(After restarting, the queue process is found to have disappeared), and then start again
View the queue process : ps -aux | grep queue
Sometimes the program goes wrong for some reason, and a large number of logs will be generated. It is best to adjust the log. Come out alone. Add at the beginning of the configuration file##Log adjustment
use think\facade\Log;Log::init([ 'single' => 'queue', 'file_size' => 1024 * 1024 * 10, 'level' => ['error'],]);
queue-cli.log file# in the
runtime
The above is the detailed content of About thinkphp-queue problem solving. For more information, please follow other related articles on the PHP Chinese website!