title: debugging long running PHP script
body: <p>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 MySQL, but it also makes a lot of HTTP calls and some SOAP).</p>
  
  <p>Now, performance is downgrading with the time. When testing  with a few records (around 100), performance is ok, it is done in a 10-20 minutes. When running whole import (about 1600 records), mean time of import of one record grows steadily, and whole thing takes more than 24 hours, so at least 5 times  longer than expected.</p>
  
  <p>Memory seems not to be a problem, usage growing as it should, without unexpected peaks. </p>
  
  <p>So, I need to debug it to find the bottleneck. It can be some problem with the script, underlying code base,  php itself, database, os or network part. I am suspecting for now some kind of caching somewhere which is not behaving well with a near 100 % miss ratio.</p>
  
  <p>I cannot use XDebug, profile file grows too fast to be treatable.</p>
  
  <p>So question is: <strong>how can I debug this kind of script?</strong> </p>
  
  <p>PHP version: 5.4.41
  OS: Debian 7.8
  I can have root privileges if necessary, and install the tools. But it's the production server and ideally debugging should not be too disrupting. </p>