Our new Indie Games subforum is now open for business in G&T. Go and check it out, you might land a code for a free game. If you're developing an indie game and want to post about it, follow these directions. If you don't, he'll break your legs! Hahaha! Seriously though.
Our rules have been updated and given their own forum. Go and look at them! They are nice, and there may be new ones that you didn't know about! Hooray for rules! Hooray for The System! Hooray for Conforming!

PHP and memory...

I am in the midst of developing a web application and despite having a decent amount of experience in web development, I never really stopped and gave a ton of thought to memory when it comes to my php scripts. However, with this project I am using zend framework and it is a decent memory hog. So I have some questions...

I am monitoring my memory use for a typical call to my site and it appears as though its somewhere around 20MB. This seems like a ton and I am actively looking for ways to decrease it. One thing I noticed is that when I call zend's date class for the first time, my memory usage shoots up 3MB. However it is pretty much untouched for other instances of this class.

So if I do
echo(memory_get_usage());
        echo('<br />');
        $this->last_login=Zend_Date::now();
        echo(memory_get_usage());
        echo('<br />');
        $this->last_active=Zend_Date::now();
        echo(memory_get_usage());
        echo('<br />');

The result is
9136448
12812408
12814496

So the jump is with that first call.

My question is, if two users are accessing the site at the same time, will they both experience that 3MB memory use? Or will the server have that class in memory so it only uses 3MB once?

Basically, if a call to the site uses 20MB of memory, will it be 20MB * the number of users. Or will the server have a lot of the information loaded into memory to subsequent calls so multiple users would use up far less memory then the initial?

I would assume the latter is the case based on the fact that reusing zend_date doesn't incur a 3MB hit every time. But without being admin of my server and hvaing tons of folks to test at once, its hard to tell.

616610-1.png

Posts

  • zeenyzeeny Registered User regular
    Basically, if a call to the site uses 20MB of memory, will it be 20MB * the number of users

    The answer is no and if you give us an actual configuration that you are running I would be able to tell you more.
    (apache + mod_php, fastcgi, fpm or whatever).
    In short, more requests will increase the memory usage, but the increase is not linear and depends significantly on your configuration and software.

    Edit: Using Zend to benchmark memory usage is not a good idea because it allocates memory following an internal protocol, IIRC.

    zeeny on
  • DisrupterDisrupter Registered User regular
    One of my big weaknesses right now is handling the configuration of the server itself. I have some limited experience with a VM of centos I was managing to learn, but I am far from an expert.

    Right now I am running off a buddy's server who is much more knowledgable about it then I am, but he is much less experienced in PHP itself. What is the best way for me to determine what the configuration is? Would the results of a phpinfo call help? Or would I need more info then that?

    Note: i believe it is apache + mod_php. I do not believe fastcgi or fpm are being used. How difficult would it be to have those set up? Would you recommend fpm over fastcgi? Should I contact my buddy and see if it would be trouble for him to install or or both?

    Disrupter on
    616610-1.png
  • zeenyzeeny Registered User regular
    Apache + mod_php - all you can do is look at the mpm's modules and configuration in the apache/httpd.conf file to see if there is a better fit for your application. Still, there is no way to avoid the overhead per process if you stick with it, but it really shouldb't be a problem though, unless your server is getting 500k+ hits per 24h,(1 request = 1 PHP process with mod_php)
    Nginx + fpm is more memory efficient first because nginx' project goal is performance on static content and second because fpm runs as a daemon. If you want, you can give it a try, but confirm that you need it before doing anything.
    My advice is - be sure you have an issue before changing.

    zeeny on
  • DisrupterDisrupter Registered User regular
    Gotcha. Yeah, its something that I doubt I will ever actually need to address, because chances are the site wont get popular. Its just something I know very little about, so I figured id do some research/ask around. Thanks for the input.

    616610-1.png
Sign In or Register to comment.