Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7568517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:56:47+00:00 2026-05-30T14:56:47+00:00

I have a lot of static JSON text content indexed in a database. Some

  • 0

I have a lot of static JSON text content indexed in a database. Some of this content is greater than 20K. Web pages request this content via Ajax and a call to a PHP file to fetch the data in the database.

Of course, one can gzip the returned content on the fly, but I was wondering whether I could fetch pre-gzipped content and return it directly from PHP. In other words, I could pre-gzip entries and store them in the database itself, rather than the full text.

Is this possible? If yes, how do I indicate in PHP that the returned content is gzipped binary? I use echo for plain text, but which command should I use for binary data? I am no expert at PHP. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:56:48+00:00Added an answer on May 30, 2026 at 2:56 pm

    You would also echo the gzipped data. echo is simply a “write these bytes to the output buffer”. You can echo images if you want. The interesting thing is, what you tell the browser to do with the data. This is where the HTTP response headers come in. You need to send a Content-Encoding header. But you need to make sure, that the client is able to understand gzip, for this to work at all. You should also know, that there are two different compression algorithms in use: DEFLATE and GZIP.

    <?php
    $data = fetchGzippedDataFromDatabase();
    if (stripos($_SERVER["HTTP_ACCEPT_ENCODING"], 'gzip') !== false) {
      header('Content-Encoding: gzip');
      header('Content-Length: ' . strlen($data));
      echo $data;
    } else {
      // client does not accept gzipped data
      echo gzdecode($data);
      // or gzinflate() or gzuncompress() 
      // depending on what you used to compress in the first place
    }
    

    You might want to consider using a reverse proxy (nginx, varnish, squid, …) and have them handle output compression.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a music related ASP.NET web site which caches a lot of static
I have a database holding a lot of static data for my current application.
I have a website with a lot of static HTML pages. There are also
We have lot of object with this kind of design : Interface and several
I have a lot of classes in the App_Code directory could this be a
I have a lot of constants that are somehow related, at some point I
So, I'm new to dynamic web design (my sites have been mostly static with
In my project I have a lot of email addresses on static sites. Is
Let's say I have this method: public static object CallMethod(Delegate method, params object[] args)
I've a website composed by some .asp file and a lot of static .html

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.