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?
PHP and Edge Side Includes (ESI)
Moderator: General Moderators
re: ESI and PHP
feyd | Please use
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.
--paulCode: 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]- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA