i have problem with my automatic generating images.

I have PHP script, which get url hash of image and generates this image in requested dimensions and modifications, by the "m" parameter in url. It can change dimensions, and stuff like this. 

With single or few pictures it is great - like: <http://www.jaarda.eu/upload/pluginGallery/129b12182490d9e191b3a7cdd4fcf704?m=wh_400-400>

But in big amount i have problems with not loading some items. Check on <http://www.jaarda.eu/>.

I dont think, it is server problem, CPUs dont go on max, and memory too. Script, which generates images even send cache headers, but still no change - on page with big amount of pictures like jaarda.eu is problem. Generating other dimensions of picture is not every time, when script fires - image is generate only once, and then is saved on server for again use. I even try multipy increase power of my VPS and no change. 

This problem is not showing in Safari, only IE, Chrome, etc...

This is end of my script, where is functional caching and type sending:

```
$modified = filemtime($file);
            if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
                $request_modified = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
                if ($modified <= $request_modified) {
                    //header('HTTP/1.1 304 Not Modified');
                    header('HTTP/1.1 304 Not Modified', true, 304);
                }
            }           
            header("Last-Modified: ".gmdate('D, d M Y H:i:s', $modified)." GMT");
            header("Cache-Control: public, max-age=7200");
            header("Expires: " . gmdate('D, d M Y H:i:s', time()+7200) . ' GMT');           
            header('Content-Length: ' . filesize($file));
            header('Content-Type: '.$type);
            readfile($file);

```

Thank you so much for ideas, how solve this problem.

**EDIT**

I have improve my situation by use ob\_ functions in my code but it is not perfect still. It is better, only one of two images are not loading, but still not perfect. Problem remains in chrome with ctrl + f5 reloading, so thanks you all for any more idea.

```
$modified = filemtime($file);
        ob_start(""); 
        if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
            $request_modified = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
            if ($modified <= $request_modified) {
                //header('HTTP/1.1 304 Not Modified');
                header('HTTP/1.1 304 Not Modified', true, 304);
            }
        }           
        header("Last-Modified: ".gmdate('D, d M Y H:i:s', $modified)." GMT");
        header("Cache-Control: public, max-age=7200");
        header("Expires: " . gmdate('D, d M Y H:i:s', time()+7200) . ' GMT');           
        header('Content-Length: ' . filesize($file));
        header('Content-Type: '.$type);
        ob_end_clean();
        ob_clean(); 
        flush();
        readfile($file);
        exit(); 

```