PHP and Edge Side Includes (ESI)

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
guarriman
Forum Commoner
Posts: 44
Joined: Thu Nov 03, 2005 4:11 am

PHP and Edge Side Includes (ESI)

Post by guarriman »

Hi.

I want to accelerate my webpages by using Akamai and ESI:
http://www.akamai.com/html/support/esi.html

but I don't know how to execute ESI directives with my Apache+PHP webserver.

Any suggestion?
guarriman
Forum Commoner
Posts: 44
Joined: Thu Nov 03, 2005 4:11 am

Post by guarriman »

I also tried with an Apache module, but it doesn't exist :(
cantos
Forum Newbie
Posts: 1
Joined: Fri Nov 10, 2006 4:49 am

re: ESI and PHP

Post by cantos »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Start by hand coding the ESI in HTML pages so you can see/learn how it works, and use the Akamai ESI debugging tools via the EdgeSuite Test Server to understand what the ESI does. Only once you understand the ESI properly you can safely start writing PHP to drive it.

You'll need to emit the ESI in the output from the PHP: for example create a function called "ESI_include_file($filename)" and from that emits the necessary ESI code. Then, whenever you need to do and edge-include you can call that function from your PHP.

Here is an example building block function ([u][b]not [/b][/u]all that you'll need!) that emits some ESI. Don't try using this as-is, but refer to it once you understand the ESI that you're trying to emit.

--paul

Code: Select all

function make_esi_include_directive($inc_url, $cachedirective, $locstr, $inc_rel_url)
	{
		
		$alt_url = "alternative_web_page.html";
		$html =  "\n<!-- Start {$locstr} URL included using ESI: '$inc_url', '$cachedirective' -->\n";
		if ($inc_rel_url > '')
				$html .=  "\n<!-- alt URL is: '$alt_url', '$cachedirective' -->\n";		$html .= "<esi:try><esi:attempt>\n";
		$html .= "<esi:include src=\"" . $inc_url . "\" ";
		if ($inc_rel_url > '')
			$html .= " alt=\"" . $alt_url . "\" ";
		$html .= "dca=\"esi\" {$cachedirective} />\n";
		$html .= "</esi:attempt><esi:except>\n";
		$html .= "<esi:assign name=\"incFileName\">'$inc_url'</esi:assign>\n";
		$html .= "<esi:assign name=\"cacheDirective\">'$cachedirective'</esi:assign>\n";
		$html .= "<esi:assign name=\"locStr\">'$locstr'</esi:assign>\n";
		$html .= "<esi:include src=\"" . ESI_FAILURE_URL . "\" onerror=\"continue\" " 
					. "dca=\"esi\" {$cachedirective} />\n";
		$html .= "</esi:except></esi:try>\n";
		$html .= "\n<!-- End {$locstr} URL included using ESI: '$inc_url' -->\n";
		return $html;
	}

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Try reading the code samples and developers guidelines that are on the page you linked to. There are loads of information available to you there.
Post Reply