Disable server cache for php to force not loading pages from cache

How can I disable cache from the ubuntu server with php and plesk control panel?
BiXma AugmentedAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
You'll have to state which specific cache you're talking about... There are many in a LAMP system.

File cache. PHP Opcache. PHP Object cache implementations. Database caches. Apache mod_cache system.

Be specific.

If you're talking about PHP Opcache, just disable this in the opcache.ini file + reload FPM or Apache, if you're running an embedded PHP interpreter.
0
BiXma AugmentedAuthor Commented:
Actually all these terms are new to me :)
I want to disable the cache of web server, lets say I am hosting a page on www.mydomain.com/myscript.php, I want that when a user access this file to always get the new version even if his ISP have cache server.
I hope this easiate the issue for you
0
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Web server is still to general.

See my list above. This might be mod_cache (unlikely) or PHP Opcache (very likely).

How you find + disable all caching is dependent on how your hosting is setup.

If you're running a dedicated server with root ssh into the box, very easy to disable all hosting.

Any other type of hosting, it's impossible, because anything one client does, effects all clients.

Be sure, if you're using any proxy software like CloudFlare or NGINX fronting Apache, you disable these too.

I can tell you, unless you do this every day, tough to disable all caching.

Best to hire someone who does this type of work daily + extract exactly what you're trying to accomplish by cache disabling + then go through your content generation process... layer by layer... to disable all caching...

To ensure www.mydomain.com/myscript.php is always a fresh version, easy way is to do something like this...

Off the top of my head Apache-2.4 will be something like, might require massaging to get working correctly...

<Files ~ "\.(html|htm|php|pl|cgi|txt)$">  
   Header set Content-Type text/html
   AddDefaultCharset UTF-8
   ExpiresByType text/html M0
</Files>

Open in new window


Where M0  means - modified time of 0 (never) - so all the extensions for scripts + content will always be expired.

Also, this may be completely different on old Apache-2.2 servers
0
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
You can also embed 100% cache busting directly in your script.

Here's a snipped of cache busing I use in all my PERL CGI scripts, you'd have to convert this to PHP...

    push(@headers, "Expires: Mon, 01 Jan 1970 00:00:00 GMT\n");
    push(@headers, "Date: $now\n");
    push(@headers, "Last-modified: $now\n");
    push(@headers, "Pragma: no-cache\n");
    push(@headers, "Cache-control: private no-cache no-store must-revalidate max-age=0 pre-check=0 post-check=0\n");
    push(@headers, "Status: $code\n");
    push(@headers, "Content-Type: text/html\n");
    push(@headers, "Location: $new\n") if $new;
    push(@headers, "\n");

Open in new window


Also this code generates redirects, so you'd embed your payload/content at the end, rather than the Location (redirect).
0
Dave BaldwinFixer of ProblemsCommented:
The biggest problem with caching is not on the server but in the web browsers.  All browsers cache files to allow them to load them quickly on the next request.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.