run php script after each request

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sentino
Forum Newbie
Posts: 5
Joined: Thu Nov 27, 2008 9:08 pm

run php script after each request

Post by sentino »

Hello, I have a multi-user web application installed on Linux working through Apache 2 and php 5. For each HTTP request, an Apache child process will be up to serve this request (I am using MMP prefork). I would like to know and save the process ID of each process. I can see this by looking into the server-status page in Apache but I want to see this using php. In php, the function posix_getpid() returns the process ID but this returns different value when another process is up to serve different request (I noticed that by refreshing the script that contains the code: echo posix_getpid();
To know and save the process ID of each request, I am thinking to find a way to run this script after each request.
1- Is this the best way to perform this task?
2- If yes, how can I make the script run after each request?
3- After I know the process ID, I want to write a C program to calculate the CPU usage of this process. Where should I save the process ID (in file, database, memcache ?) to be able to pass it to the C program?
Post Reply