By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,674 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

Cause of a large memory allocation difference on two different machines?

100+
P: 310
I have just noticed a very large difference in memory usage for the PHP applications that I have developed for my company between my developmental machine and the "production" machine:

Development PC: PHP version 4.3.9 on a 32 bit using Linux Centos 4.5 as operating system.

Production machine: PHP version 5.1.2 on a 64 bit machine with Linux Novell Suse 10.1 as operating system.

I noticed this because I started to get memory limit exceeded errors on some page requests for one of the applications. Out of curiosity I inserted this line at several locations in the scripts to get an idea of the difference in memory usage between the two machines:

Expand|Select|Wrap|Line Numbers
  1. echo "memory = " . memory_get_usage(true) . "<br>";
  2.  
The table below shows an example output. The first column is from the 32 bit machine, the second is from the 64 bit machine, and the 3rd column is the difference. Each row represents a later location in the scripts.

Expand|Select|Wrap|Line Numbers
  1. PHP4        PHP 5    difference
  2. 3179336        2018056    1161280
  3. 4347824        2729504    1618320
  4. 5870144        3665760    2204384
  5. 5921784        3698664    2223120
  6. 6442704        4033856    2408848
  7. 8374136        5034368    3339768
  8.  
This large difference between the two machines really surprises me. Does anyone know what the primary cause may be? Is it because of the 32bit vs. 64bit architecture? Or is it because of the PHP4 vs. PHP5 versions?



[P:S: It may seem strange that I am developing applications with PHP4 that are intended to be deployed with PHP5. For the curious, here are the reasons: 1) the production server is new and I have not had a chance to upgrade the development machine, 2) so far it seems to work and 3) the new management at this small startup company has decided to outsource all IT related needs and purchase commercial software and my position has actually been terminated (I am currently looking for new work), hence there is no incentive to upgrade the development machine :) ]
Sep 15 '08 #1
Share this Question
Share on Google+
7 Replies


Atli
Expert 5K+
P: 5,058
My guess would be the PHP version.

Although there is really no way to know without knowing what the code is doing.
Could be any number of things.

I don't see why the 32bit vs 64bit processors would cause this. The amount of data stored shouldn't be affected.
Sep 15 '08 #2

100+
P: 310
I am thinking that the 64 bit machine maybe by default is storing character data with a larger number of bytes per character. Maybe this is not something that the machine is doing because it is 64 bit, but because it is a different Linux installation or perhaps a combination of both.

Another explanation would be that the combination of this Linux and 64 bit architecture stores numeric data per default at a higher precision?

I just cannot see why the PHP5 over PHP4 would use so much more memory.

There are two large sinks of memory in my application. The first is due to the large amount of code that is included via require statements. I certainly do not include everything, but the classes that I have built up do contain a lot.

The second memory sink is due to the manner in which I build up a complex page with my own table, row and cell classes, and then echo all at once to the user at the end of the script. Pages showing complex process flows or distributions of wafers on chips result in large amount of HTML elements, all stored in objects until they are printed out at once.
Sep 15 '08 #3

Atli
Expert 5K+
P: 5,058
I am thinking that the 64 bit machine maybe by default is storing character data with a larger number of bytes per character. Maybe this is not something that the machine is doing because it is 64 bit, but because it is a different Linux installation or perhaps a combination of both.
I doubt it stores the characters any differently. Each character set has a predefined size *per character* and both PHP versions should be using the same character set.
There would be no point in spending more than is needed.

Another explanation would be that the combination of this Linux and 64 bit architecture stores numeric data per default at a higher precision?
It could be. But, still, that doesn't make sense. It was the 64bit machine that had lower memory usage, right?

I just cannot see why the PHP5 over PHP4 would use so much more memory.
It could be that PHP5 is just designed to handle data differently.
Before PHP5, OOP wasn't really that good, and predicting the increase in OOP usage, and consequently the amount of files that need to be incuded, perhaps they improved the way PHP includes files and/or handles arrays (objects act much like arrays, so that would make sense).

But I don't really know. Just guessing here.
Sep 15 '08 #4

pbmods
Expert 5K+
P: 5,821
Heya, Coolsti.

PHP 5 does have a problem with objects with recursive references (http://bugs.php.net/bug.php?id=33595). Looks like that won't be fixed until PHP 5.3.

I've heard that some people have memory problems after upgrading from 5.1 to 5.2, but I am not familiar with differences in memory usage between 4 and 5.
Sep 15 '08 #5

100+
P: 310
Thanks for the tips and replies!

To Atli, no, it is the PHP5 on the 64 bit machine which is using more memory.

I solved this issue by just increasing the allowable memory usage per page request. I would dig deeper into it if it wasn't for the fact that I am fired and management will probably eventually abandon the work that I have done here anyway. I will be here doing this still (although without much enthusiasm) until I find a new job or until the end of January, which ever comes first. So there is not much incentive for me to find out the real reason for the extra memory usage, be it due to architecture or PHP 5 bugs.

Interestingly enough, a major difference in memory usage can be seen in the first 3 rows of my above table, and these show_memory_usage outputs were placed in between sucessive require_only calls to load in needed classes. And here, the classes being loaded in are not really doing anything yet, but just becoming read in and made available. That is, class objects are not being created here.
Sep 15 '08 #6

Markus
Expert 5K+
P: 6,050
for the fact that I am fired
That's a shame! I wish you all the best.

Good day.
Sep 15 '08 #7

Atli
Expert 5K+
P: 5,058
To Atli, no, it is the PHP5 on the 64 bit machine which is using more memory.
Ahh ok. Isn't your table in the first post backwards then? It's shows PHP5 with the lower numbers. (... I think)

Anyways, good luck with the Job hunt.
Sep 15 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.