Current time: 01-17-2021, 06:37 PM Hello There, Guest! (LoginRegister)

Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use Persistent Connections (keep-alive)
07-16-2010, 03:39 AM
Post: #2
RE: Use Persistent Connections (keep-alive)
Hey Marvin,

I had the same problem before with my coldfusion pages when I started to use GZIP for the main document.

You need to set a php header for content length.

For coldfusion I did something like this:

Code:
<cfsavecontent variable = "raw">
content here...
</cfsavecontent>

<cfset gmt = gettimezoneinfo()>
<cfset gmt = gmt.utcHourOffset>

<cfif gmt EQ 0>
   <cfset gmt = "">
<cfelseif gmt GT 0>
   <cfset gmt = "+" & gmt >
</cfif>

<cfset filePath = "#GetCurrentTemplatePath()#">
<cfset fileObj = createObject("java","java.io.File").init(filePath)>
<cfset fileDate = createObject("java","java.util.Date").init(fileObj.lastModified())>
<cfset fileDate = '#DateFormat(fileDate, 'ddd, dd mmm yyyy')# #TimeFormat(fileDate, 'HH:mm:ss')# GMT#gmt#'>

<cfif cgi.HTTP_ACCEPT_ENCODING contains "gzip">
  
  <cfset raw = #htmlCompressFormat(raw, 2)#>
  
  <cfscript>
  fileOut = createobject("java", "java.io.ByteArrayOutputStream").init();
  out = createobject("java","java.util.zip.GZIPOutputStream").init(fileOut);
  out.write(raw.getBytes(), 0, len(raw.getBytes()));
  out.finish();
  out.close();
  </cfscript>
  
  <cfheader name="Content-Encoding" value="gzip">
  <cfheader name="Last-Modified" value="#fileDate#">
  <cfheader name="Content-Length" value="#len(fileOut.toByteArray())#">
  <cfheader name="Expires" value="#GetHttpTimeString(DateAdd('d', 7, Now()))#">
  <cfcontent type="text/html; charset=utf-8" reset="true" variable="#fileOut.toByteArray()#">  
    
<cfelse>
  <cfheader name="Expires" value="#GetHttpTimeString(DateAdd('d', 7, Now()))#">
  <cfheader name="Last-Modified" value="#fileDate#">
  <cfoutput>#htmlCompressFormat(raw, 2)#</cfoutput>
</cfif>

Hope this helps.

Sincerely,
Travis Walters
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Use Persistent Connections (keep-alive) - green-watch.org - 07-16-2010 03:39 AM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)