debugging long running PHP script

后端 未结 11 2399
我寻月下人不归
我寻月下人不归 2021-02-19 06:46

I have php script running as a cron job, extensively using third party code. Script itself has a few thousands LOC. Basically it\'s the data import / treatment script. (JSON to

11条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-19 06:58

    Okay, basically you have two possibilities - it's either the ineffective PHP code or ineffective MySQL code. Judging by what you say, it's probably inserting into indexed table a lot of records separately, which causes the insertion time to skyrocket. You should either disable indexes and rebuild them after insertion, or optimize the insertion code.

    But, about the tools.

    You can configure the system to automatically log slow MySQL queries: https://dev.mysql.com/doc/refman/5.1/en/slow-query-log.html

    You can also do the same with PHP scripts, but you need a PHP-FPM environment (and you probably have Apache). https://rtcamp.com/tutorials/php/fpm-slow-log/

    These tools are very powerful and versatile.

    P.S. 10-20 minutes for 100 records seems like A LOT.

提交回复
热议问题