debugging long running PHP script

后端 未结 11 2852
我寻月下人不归
我寻月下人不归 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

    There are three things that come to mind:

    1. Set up an IDE so you can debug the PHP script line by line
    2. Add some logging to the script
    3. Look for long running queries in MySQL

    Debug option #2 is the easiest. Since this is running as a cron job, you add a bunch of echo's in your script:

    Then pipe stdout to a log file in the cron job command.

    01 04 * * * php /path/to/script.php >> /path/to/script.log
    

    Now you can add log_message('info|warn|debug|error', 'Message here') all over the script and at least get an idea of where the performance issue lies.

    Debug option #3 is just straight investigation work in MySQL. One of your queries might be taking a long time, and it might show up in a long running query utility for MySQL.

提交回复
热议问题