2020-9-7 14:18:37 星期一
PHP官方的kafka擴展是 rdkafka;
kafka PHP官方擴展文檔: https://arnaud.le-blanc.net/php-rdkafka-doc/phpdoc/book.rdkafka.html
kafka 配置項的官方說明: https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md
下載擴展: http://pecl.php.net/package/rdkafka
windows 安裝擴展: https://arnaud.le-blanc.net/php-rdkafka-doc/phpdoc/rdkafka.installation.windows.html
4.0以后的版本有一個重要改動:
BREAKING CHANGE: Since version 4.0, the client no longer polls for network events at shutdown (during object destructor). This behaviour didn't give enough control to the user in case of server issue, and could cause the script to hang while terminating. Starting from 4.0, programs MUST call flush() before shutting down, otherwise some messages and callbacks may be lost.
簡單翻譯一下:
對於4.0以后的版本, 客戶端對象銷毀的時候, 不再檢查處理(poll)網絡事件了, 因為如果服務器有問題, 用戶也干不了啥, 而且會導致腳本掛起;
以后在程序停掉之前必須調用 flush()方法, 否則會導致消息丟失.
==============
如果報錯 Segmentation fault (core dumped) 檢查一下是不是topic沒有配置或者其他配置項配置錯誤了 (php5.6 rdkafka 4.0.2)