溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么解決thinkphp-queue的相關(guān)問題

發(fā)布時(shí)間:2021-02-24 10:02:49 來源:億速云 閱讀:750 作者:清風(fēng) 欄目:編程語言

這篇“怎么解決thinkphp-queue的相關(guān)問題”除了程序員外大部分人都不太理解,今天小編為了讓大家更加理解“怎么解決thinkphp-queue的相關(guān)問題”,給大家總結(jié)了以下內(nèi)容,具有一定借鑒價(jià)值,內(nèi)容詳細(xì)步驟清晰,細(xì)節(jié)處理妥當(dāng),希望大家通過這篇文章有所收獲,下面讓我們一起來看看具體內(nèi)容吧。

thinkphp是什么

thinkphp屬于一種免費(fèi)的開發(fā)框架,能夠用于開發(fā)前端網(wǎng)頁,最早thinkphp是為了簡化開發(fā)而產(chǎn)生的,thinkphp同時(shí)也是遵循Apache2協(xié)議,最初是從Struts演變過來,也把國外一些好的框架模式進(jìn)行利用,使用面向?qū)ο蟮拈_發(fā)結(jié)構(gòu),兼容了很多標(biāo)簽庫等模式,它能夠更方便和快捷的開發(fā)和部署應(yīng)用,當(dāng)然不僅僅是企業(yè)級(jí)應(yīng)用,任何php應(yīng)用開發(fā)都可以從thinkphp的簡單、兼容和快速的特性中受益。

mysql超時(shí)斷線問題

隊(duì)列任務(wù)運(yùn)行一段時(shí)間,出現(xiàn):SQLSTATE[HY000]: General error: 2006 MySQL server has gone away報(bào)錯(cuò)。

解決方法和分析:

配置文件database.php中配置斷線重連:

  // 是否需要斷線重連
  'break_reconnect'  =>  true,
  // 斷線標(biāo)識(shí)字符串
  'break_match_str'  => ['2006'],

配置后雖然日志中會(huì)出現(xiàn)另一個(gè)報(bào)錯(cuò):PDO::prepare(): send of 60 bytes failed with errno=32 Broken pipe,但并不影響程序運(yùn)行結(jié)果。因?yàn)閿嗑€重連后,程序都會(huì)拋出錯(cuò)誤:

...} 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;}

如何在docker環(huán)境進(jìn)行進(jìn)程監(jiān)護(hù)

一般情況下,可以使用supervisor監(jiān)護(hù)隊(duì)列進(jìn)程。配合docker使用的話,大概有幾方案:

1.將supervisor安裝到php服務(wù)所在的容器中

2.跑一個(gè)新的容器來運(yùn)行隊(duì)列任務(wù)(不用supervisor,容器本身是一個(gè)daemon)

3.直接在現(xiàn)有的php容器運(yùn)行隊(duì)列任務(wù)(命令行使用–daemon選項(xiàng))

方法一supervisor參考配置(放在/etc/supervisor/conf.d, 文件命名為{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

方法二新開一個(gè)鏡像參考配置(在docker-compose.yml中添加服務(wù)):

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

方法三有點(diǎn)hack,為了不大改線上環(huán)境,最后使用方法三(在host機(jī)子操作)。

啟動(dòng):docker exec -i php7 php /path/to/think queue:work --queue=my-queue-name --sleep=3 --daemon

重啟:docker exec -i php7 php /path/to/think queue:restart (重啟后發(fā)現(xiàn)隊(duì)列進(jìn)程消失了),然后再啟動(dòng)

查看隊(duì)列進(jìn)程: ps -aux | grep queue

日志調(diào)整

有時(shí)候某些原因程序出錯(cuò),會(huì)有大量日志生成,最好調(diào)整下日志,單獨(dú)出來。在配置文件config/queue.php開頭添加:

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

日志將輸出到runtime目錄的queue-cli.log文件                      

感謝你的閱讀,希望你對“怎么解決thinkphp-queue的相關(guān)問題”這一關(guān)鍵問題有了一定的理解,具體使用情況還需要大家自己動(dòng)手實(shí)驗(yàn)使用過才能領(lǐng)會(huì),快去試試吧,如果想閱讀更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注億速云行業(yè)資訊頻道!

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI