Reputation: 3612
I have a self-made "Process Manager" for my site, that simply parses the shell command
ps aux | grep php
This is useful to see if a php process is taking too much CPU or MEM. However, sometimes I see some php processes delaying some time to complete. The problem is that this doesn't tell me much:
/usr/bin/php /home/mysite/public_html/process.php
Because, a process may depend a lot of what GET arguments it receives.
So, my question is, is it possible to know what GET arguments did a PHP process receive?
Thank you.
Upvotes: 4
Views: 11679
Reputation: 2508
If you want to see details of your progress on linux console via ps you have to use proctitle this pecl extension will give you
setproctitle() function.
extension is very old but still working even zts mode.
If you are using cli version you can use : cli-set-process-title() this is native php function (version PHP5 >=)
So simple code that i use to track on linux :
<?
if ((PHP_SAPI === 'cli' OR defined('STDIN'))) {
$tmp = $_SERVER["argv"];
unset($tmp[0]);
$text = "/". implode('/',$tmp);
@cli_set_process_title (urldecode($text));
} else {
@setproctitle (urldecode($_SERVER["REQUEST_URI"]));
}
?>
I just write this to top index.php on codeigniter.
For see processes uses most cpu and memory at linux :
ps o pid,stat,time,pcpu,pmem,cmd -C php --sort -pcpu
now you will able to see processes
Upvotes: 0
Reputation: 1
if somebody needs answeer to this problem, i can send commands from apache server to ubuntu console, just: add www-data user permissions in sudoers file.
www-data ALL=(ALL) NOPASSWD:ALL
and execute command from php file
$comand2= shell_exec('sudo -S service cron restart 2>&1' );
echo "<pre> $comand2 $</pre>";
Upvotes: 0
Reputation: 496
Only problem is GET parameters are passed onto your script only when called via your web server and not from the command line, in your case your only going to get ARGS.
You can always do a grep on :
$ ps -auwwwx | grep my_php_script
to see the ARGs in the command line scripts
Upvotes: 0