记忆策略

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

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.

PHP's memory allocation is per call. In many PHP models (e.g. fcgi) one PHP process doesn't know about the others, so this is the only practical version.

So: No, this will not throw an allocation error, but it will use 100MB

To limit total memory usage, you have to limit concurrency and per-call usage in concert.