I store all my images behind the webroot (before /var/www/), meaning the net server is not able to transmit cache headers back for my pictures. What should i add to create anyone's web cache work? Presently, this really is getting hit each time through the same browser.

My <img> path on my small pages look something similar to this:

<img src="pic.php?u=1134&i=13513&s=0">

Edit: Can it be that it's because "pic.php?u=1134&i=13513&s=0" isn't a valid file title or something like that?

// pic.php

    // open the file in a binary mode
    $user = $_GET['u'];
    $id = $_GET['i'];
    $s = $_GET['s'];

    if (!isset($user) && !isset($s) && $isset($id))
    	// display a lock!

    require_once("bootstrap_minimal.php"); //setup db connection, etc

    // does this image_id belong to the user?
    $stmt = $db->query('SELECT image_id, user_id, file_name, private FROM images WHERE image_id = ?', $id);
    $obj = $stmt->fetchObject();

    if (is_object($obj))
    	// is the picture is the users?
    	if ($obj->user_id != $_SESSION['user_id'])
    		// is this a private picture?
    		if ($obj->private == 1)
    			// check permissions...
    			// display a lock in needed!
    	// display a error pic?!

    if ($s == 0)
    	$picture = $common->getImagePathThumb($obj->file_name);
    	$picture = $common->getImagePath($obj->file_name);

    // send the right headers
    header("Content-Type: image/png");
    header("Content-Length: " . filesize($picture));

    $fp = fopen($picture, 'rb');

    // dump the picture and stop the script

You have to add something similar to:

$expiry = 3600*24*7; // A week
header('Expires: ' . gmdate('D, d M Y H:i:s' time() + $expiry) . ' GMT');
header('Cache-control: private, max-age=' . $expiry);

Apache only caches static files automatically. You have to send a cache control header through the header() function. This article provides extensive info on the subject.

Alternatively, you could utilize the PHP file to redirect towards the actual location from the image. (This really is most likely the simplest way if you do not know anything about headers.)

You could try:

header("Cache-Control: max-age=3600");

Which should send a cache timeout of 1 hour around the file.

Things I would do in you are to stream the bytes from the image utilizing a .php file. Don't connect to images directly rather, connect to a php file that: - results the cache headers - reads the file from disk, from behind the webroot - transmits the look bits lower the wire

Simple answer: you are not telling your users' browser to cache it