1

How can I check which file a current php instance is running?

I am on a VPS with shared resources and continue to hit my quota - yet I don't know where to start to investigate which php file is causing high memory issues

I would like to set up a cron job that runs a linux command or a php script that will tell me what the current state is of the php instance and what files are running and how much memory they are consuming

GregM
  • 3,624
  • 3
  • 35
  • 51
  • 1
    do you have access to ps? `ps -ax | grep php` – Dave Jun 12 '14 at 12:10
  • If your PHP apps are running out of memory surely they're causing out of memory errors in the event log, could you check that first? – scragar Jun 12 '14 at 12:11
  • ps -ax states bad parameter – GregM Jun 12 '14 at 12:14
  • @scragar What type of logs are available for memory errors? I see a lot of http error log files, but not sure where memory logs are stored... – GregM Jun 12 '14 at 12:16
  • @morty346 Your PHP error log should contain the errors. It's `/var/log/php_error` on my CentOS VM, and in my XAMPP install it's `C:\xampp\php\php_error.log` - In general it's in the same directory as PHP itself or /var/log, but that can be changed in your PHP.ini file, so if it's not in a default location check the configuration of your server. – scragar Jun 12 '14 at 12:17
  • @scragar not seeing one... here is what I see http://pastebin.com/d7REzCp8 (this is in /var/log) – GregM Jun 12 '14 at 12:20
  • @Dave $ ps -ax bash: $: command not found $ Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html – GregM Jun 12 '14 at 12:23
  • Try searching your PHP.ini file for `error_log`, that will contain the path of your log file. `grep 'error_log' /etc/php.ini` – scragar Jun 12 '14 at 12:23
  • @scragar perhaps im blind - but I don't see it in there http://pastebin.com/3fqEtH3P – GregM Jun 12 '14 at 12:28
  • @Dave if I disregard the bad syntax warning - it only shows that php53.cgi is running it doesn't show me anything about which file – GregM Jun 12 '14 at 12:29
  • `ps-a` depending on your platform. does it show one PHP instance or multiple? – Dave Jun 12 '14 at 12:32
  • @scragar I added log_errors = 1 and error_log = PATH to php.ini – GregM Jun 12 '14 at 12:33
  • @Dave $ ps -a doesn't show much of use - assuming you mean ps ax? then that shows multiple ps ax | grep php 11226 ? S 0:00 php53.cgi 14030 pts/1 S+ 0:00 grep php 23415 ? S 0:05 php53.cgi – GregM Jun 12 '14 at 12:35
  • look at the answer (O votes) here http://stackoverflow.com/questions/13836307/how-to-prevent-php-script-running-more-than-once – Rachel Gallen Jun 12 '14 at 12:37
  • he said he isn't getting the script name in ps – Dave Jun 12 '14 at 12:42

1 Answers1

1

if the error logging that @scragar suggested doesn't give you fruit, you could have all your (suspect) php files dump their process id into the error log with getmypid() which will give you a timestamp to correlate with your cron job of ps ax allowing you to match up piggy processes gobbling up memory with the pid of the file

error_log ( __FILE__.' pid='.getmypid());

Dave
  • 991
  • 1
  • 7
  • 15
  • That makes sense - appreciate it will investigate after I get a bit of data in the logs – GregM Jun 12 '14 at 12:47