Jump to content

Size of PHP Process?


mlewisct

Recommended Posts

I have a Joomla Site where users authenticate, then they can link to an online game that is not a Joomla component - just a PHP program.   When I examine the processes running on the server, I see several and all show memory usage around 87MB.   

 

Since I don't store very much in the session - only a few keys, I don't know why memory usage should be so high for the process, nor can I tell from the process list if these are the game PHP program, or the Joomla session.

 

What determines the size of a PHP process (in memory)?   

 

Is there an easy way to tell if the process is the game or the Joomla session?

 

I am very limited in what I can see due to GoDaddy shared hosting.

Link to comment
Share on other sites

Use something like memory_get_usage to determine how much memory your scripts are using, rather than look at something like the output of top (or other process list). The amount of memory reported by a process listing program can be mis-leading do to how things like shared libraries work. For example the PHP engine will need memory for the PHP executable itself + all the loaded extensions (GD, Mysql, Zip, etc). When you run multiple instances of PHP though, they all references the same shared library code, so only the core php executable gets duplicated and needs more memory. A process listing would show both as if they each had their own copy of the libraries loaded though.

 

Just to maybe help explain better, lets throw some theoretical numbers in:

Say your PHP executable needs 10MB of memory to be loaded and run. When it runs, it loads the following extensions w/ their own memory requirements:

GD: 4MB

MySQL: 7MB

Zip: 3MB

PDO: 9MB

 

So the first instance of PHP that gets run needs to load up itself + the libraries into RAM, requiring a total of 33MB of memory. This is what would be reported by a tool like top that lists processes.

 

The second instance of PHP you start needs to load a second copy of the PHP executable into RAM, but it can reference the already existing copies of the libraries. As such it only requires an additional 10MB of memory to run. A tool like top would still report it as using 33MB of memory though, counting the libraries again.

 

So if you checked the process list you'd see two instances of PHP each using 33MB of memory for a total of 66MB used. In reality though there is only 43MB of memory being used, since the shared libraries are, as the name implies, shared between the two processes.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.