Home  >  Article  >  PHP Framework  >  About thinkphp-queue problem solving

About thinkphp-queue problem solving

藏色散人
藏色散人forward
2021-02-23 15:13:295434browse

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

The queue task runs for a while Time, appears: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away. Solution and analysis:

Configuration file

database.php

Configure 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-&gt;isBreak($e)) {  return $this-&gt;close()-&gt;query($sql, $bind, $master, $pdo);  }  throw new PDOException($e, $this-&gt;config, $this-&gt;getLastsql());} catch (\Throwable $e) {  if ($this-&gt;isBreak($e)) {  return $this-&gt;close()-&gt;query($sql, $bind, $master, $pdo);  }  throw $e;} catch (\Exception $e) {  if ($this-&gt;isBreak($e)) {  return $this-&gt;close()-&gt;query($sql, $bind, $master, $pdo);   }  throw $e;}</pre>

How to monitor the process in the docker environment

Under normal circumstances, you can use supervisor to monitor the queue process. If used with docker, there are probably several options: 1. Install supervisor into the container where the php service is located

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 --daemon

Restart: 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

##Log adjustment

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

config/queue.php:
use think\facade\Log;Log::init([
    'single'    => 'queue',
    'file_size' => 1024 * 1024 * 10,
    'level'     => ['error'],]);

The log will be output to the

queue-cli.log file# in the runtime

directory. ##                                                                                                                                                                                 

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!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete