Forum Moderators: coopster

Message Too Old, No Replies

know the process ID of each request

         

alluoshi

4:18 pm on Jan 29, 2009 (gmt 0)

10+ Year Member



Hi, 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 service this request (I am using MMP prefork). I would like to know and save the process ID of each process. Apache logs each request with some information by default. I can log the process ID of each request in Apache but I want to do 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();
I want this in php because ultimately I want to report the number of sessions and information about each session (like start_time and end_time of the session, IP address, username, session ID and all the processes' IDs that belong to this session)
What is the best way to do this? for example, Is there a way to have my script that contains "echo posix_getpid();" refreshed for each request? or is there a way to read from Apache log file from php and to interpret this data?
Thank you

coopster

10:56 pm on Jan 30, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



To do the reverse you can push variables into your log files -- an example here [webmasterworld.com].

To get Apache variables for use in your program, you either pull them from the pre-defined variables ($_SERVER, $_ENV) or may be able to use some of the Apache functions [php.net], depending on your particular server set up.

I'm not certain if this is the right direction or not, you will have to investigate: Process Interaction Streams [php.net] which is linked from the PHP manual page on Process Control Extensions [php.net]. However, I think we are heading down the wrong path at this point.