1

okay, so here is a quick example of code in a template, page.php, file:

<?php print_r(getdate ()); ?>

Website is setup with WPEngine. When logged in (into wordpress) works 100% and date/time changes every refresh. When logged out, it "procs" on the first visit, and stays on the same date/time for every user, no matter how many times you refresh. The only way to "update the clock" is to Purge All Cache manually, though admin. I need it to update on every refresh for everyone.

Things I tried that didn't work:

  • I assumed it was WPEngine's Cache, so it was disabled (wpengine). Nothing.
  • I tried setting "define( 'WP_CACHE', FALSE );" in wp-config.php to FALSE. Nothing.
  • It's not a plugin. There are 3 on the website - Contact Form 7, Breadcrumb NavXT and Custom Global Variables.

It's not the first time I encounter this problem, but I still have no idea how to fix it.

What do?

P.S. Yes, I know "just use js", I just gave it as an example. I need PHP to refresh, not find a workaround in js. I already did that before :)

  • You may have turned off object caching, but that's not the same thing as full page caching. Object caching is when you fetch a post and save it so you don't have to fetch it twice. You want object caching, it speeds up WP significantly. Full page caching of the final product is the issue here. WP Engine support can help you there. Keep in mind that fast scalable sites don't generate dynamic content like this for logged out users, and if they have differing content, they use dynamic URLs when possible to avoid problems such as browser cache – Tom J Nowell Apr 5 '17 at 16:00
0

This sounds like page caching. Page caching is a good thing, it keeps your site fast. The downside is that any personalized data is not accurate, which is why the clock is not updated.

It looks like perhaps WPEngine doesn't give you control over page caching - https://wpengine.com/blog/no-caching-plugins/

You may need to speak to them about a workaround for this. However, in my experience, it might be a hard sell.

Can I ask why this needs to be done in PHP? It seems to me that the performance tradeoff is not worth the gain.

  • Well, in my current project, the client wants dynamic, global testimonies on the page. I mentioned "Custom Global Variables" plugin - it has all the testimonials in the $GLOBALS variable array, that I grab a random one from on page load. Considering those are set in the admin, I can, but I don't really want to "load all of them hidden into HTML, and use JS to show one randomly". Similar item in a different project - choosing randomly from 1-10 backgrounds that are set in a Custom Field, same problem, same not amazing solution. – BlueLight Apr 5 '17 at 15:41
  • In this case, instead of loading all of the testimonials into $_GLOBALS, you could load the page and then pull a random one in via AJAX. That would solve the problem and avoid all the messy global stuff. – Welcher Apr 6 '17 at 12:52
  • how would I do that via AJAX? unless you mean run an ajax get onto a page, that should return a random testimonial, kinda like an api? – BlueLight Apr 6 '17 at 14:50
  • When the page loads, fire an AJAX request - to either admin-ajax.php or better yet a custom endpoint - that returns the markup for the testimonial you want to display and then add it to the page. – Welcher Apr 6 '17 at 16:27
  • Yeah, that's what I did. welp... I don't feel super good about it, and it's not perfect, but it works, so I guess we're good there. Thanks! :) – BlueLight Apr 6 '17 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.