doumo3903 2012-10-22 23:17
浏览 16
已采纳

记忆策略

I have a few questions that I have been searching answers for.

1: Php memory allocation.

If I have a 1 megabyte variable $img =file_get_contents('imageUrl');

and my php memory allocation is 64 megabytes, and 100 people are accessing the script at the same time, Is that going to cause a memory allocation error?

2: How would I better save an image from a url? I am getting a memory allocation warning...

if ($fileName){
    //check to make sure filename is not taken
    if(!file_exists("img/".$fileName.$fileExt)){
            $image = file_get_contents("someURL".$fileName.$fileExt);
        //check to make sure the filesize is not rediculous 8 Megabytes.
        if(strlen($image) < (8 * 1048576)){                     
            if(file_put_contents("img/".$fileName.$fileExt, $image)){
                usleep((0.25 * 1000000)); //rest 1/4 second
                    if(!image_resize("img/".$fileName.$fileExt, 202, 202, 1))die('no rezize');
            //PRETEND THERE ARE CLOSING CURLY BRACES THANKS
  • 写回答

2条回答 默认 最新

  • dsfdsf23423 2012-10-22 23:21
    关注

    Assuming you are talking about the memory_limit configuration directive, that is a limit on the amount of memory each script execution can consume, so the limit is 64M per user accessing concurrently, rather than 64M total for all users simultaneously and you would not exceed it. Its purpose is to prevent, for example, one script attempting to resize a giant image that requiring hundreds of Megabytes of memory to complete, or a runaway loop accumulating a big data string without terminating, not to place a cap on possible concurrent access.

    This is not to say that you could not exhaust the server's available memory with too much concurrency on a script though. In that case, the server would likely start paging, and have a very negative effect on performance. It should not error and stop responding to requests, however.

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

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题