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

20,389
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'.

Share:
20,389
Aram Alipoor
Author by

Aram Alipoor

I love simple and elegant solutions to complex problems. If you ask my skills I'd say: Building and maintaining cloud infrastructure, CI/CD pipelines, monitoring and logging solutions. Configuring, load-testing and optimizing many services like databases, messaging brokers, etc. Helping decouple and migrate legacy monoliths to micro-services architecture. I know a thing or two about: High-availability Containers & Isolation Monitoring & Alerting Clustering & Replication Multi-tenancy & Security Migrating monoliths to Cloud Load-balancing solutions Storage solutions Software-defined networks Distributed systems Performance optimization Load-testing Horizontal scaling solutions Building automation tools Building tools for developers On-call & Troubleshooting Backups & Disaster recovery Post-mortem reporting Writing docs & guides

Updated on July 09, 2022

Comments

  • Aram Alipoor
    Aram Alipoor almost 2 years

    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.

  • Admin
    Admin almost 13 years
    Thank you it works, but what are the numbers shown here? 1025 19622 0.0 0.0 5336 1308 ? S 02:15 0:00 wget -q http://www.example.com/sample.php
  • Marc B
    Marc B almost 13 years
    parent process id, process ID, cpu usage, memory usage, etc... look at man ps for details.
  • Krzysztof Przygoda
    Krzysztof Przygoda over 8 years
    Unfortunately, I'm getting Error, do this: mount -t proc proc /proc.