How to get list of running php scripts using PHP exec()?

前端 未结 4 1203

I need to know and kill if there is any processes running a specified PHP script. Is that possible to get list of processes running sample.php using exec() and a php script.

相关标签:
4条回答
  • 2020-12-17 04:03

    There isn't. Because PHP is ran through apache/nginx. In case of command-line-access, proccess is named PHP, not actual name of your script.

    0 讨论(0)
  • 2020-12-17 04:16
    exec("ps auxwww|grep sample.php|grep -v grep", $output);
    

    This would only work, though, if PHP is running in CGI mode. If it's running as a SAPI type thing, you'll never see "sample.php" in the process list, just 'httpd'.

    0 讨论(0)
  • 2020-12-17 04:22

    this helped me kill rogue processes via a url parameter. i figured i'd contribute to the discussion in case someone else is still poking around for answers.

    load yikes.php. identify the process id (it should be the first integer you come to in each index of the array). copy and paste it into the url as ?pid=XXXXX. and it's gone.

    //http://website.com/yikes.php?pid=668
    $pid = $_GET['pid'];
    exec("ps auxwww|grep name-of-file.php|grep -v grep", $output);
    echo '<pre>';
    print_r($output);
    echo '</pre>';
    //
    exec("kill $pid");
    
    0 讨论(0)
  • 2020-12-17 04:26

    It depends on lots of factors including OS, PHP version, etc., but you could try using signals to get a script to give you its name and then terminate if it matches. Or, have the script register its pid and then compare with running processes.

    http://stuporglue.org/handling-signals-in-php/

    0 讨论(0)
提交回复
热议问题