doujiao7325 2010-03-16 17:03
浏览 82
已采纳

我怎么知道我的PHP应用程序是否使用了太多内存?

I'm working on a PHP web application that let's users network with each other, book events, and message eachother. There's only about 100 users.

I set up the application on a VPS with Ubuntu 9.10, apache2, mysql 5 and php 5. I had 360 Mb of RAM, but upgraded to 720 MB.

Lately, my web application has been experiencing outages due to excessive memory usage. From what I can tell in error logs, it seems the server automatically kills apache processes that consume too much memory. As a result, I upgraded memory from 360 MB to 720 MB as a stop-gap measure.

So my question is, how do I go about resolving these outage issues? How do I know if my website's need for more memory is due to poor code or if it's part of the website's natural growth? What's the most efficient way to determine which PHP scripts consume the most memory?

  • 写回答

4条回答 默认 最新

  • duanqiang6501 2010-03-16 23:37
    关注

    There's no simple answer to this, although I would suspect that it may a problem in your code.

    What is the memory_limit setting in your php.ini file? Typically I'd recommend at least 4Mb, and usually 16. How many concurrent hits are you fielding? Is the site doing a lot of heavy reporting of stats? Or rendering of images via PHP? Do you use file_get_contents() anywhere?

    You really need to set up some custom logging to report for each URL, the size of the log file at exit. e.g. you could auto-prepend:

    <?php
    register_shutdown_function('log_mem');
    
    function log_mem()
    {
       fputs(STDERR, '[' . date('c') . '] ' . memory_get_usage() . ' ' 
         . $_SERVER["REQUEST_URI"] . "
    ");
    }
    

    (Note - no closing tag) This will write out the memory used by each PHP page to the error_log so you can isolate the problem more easily.

    HTH

    C.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥35 基于python的有ssl加密传输的socket聊天室
  • ¥15 数码管亮度控制器设计
  • ¥15 kafka客户端跨网段访问,看日志提示连接的还剩内网地址,且访问不通
  • ¥15 关于c语言代码的问题
  • ¥15 c51单片机控制步进电机
  • ¥20 Visual studio无法检测到设备
  • ¥30 vue 页面窗口放大或者缩小元素会变化
  • ¥15 questasim仿真报错
  • ¥15 寻找电脑攻防的导师,有问题请教一下。
  • ¥20 微信同是win11,我的电脑安装不了pageoffice,一直无法打开