Caching .php file

Hi,

I have a emergency situation where i need to serve cached php file (too many users online and my hosting provider blocking my webpage).

The php file is generating json object for my mobile app and since it doesn’t have to change that often I decided to cache it. I have simply put the generated JSON msg in the file (still named getfeed.php) but cannot change the file extension as its part of the API (would need to update mobile app to point to new extension file)

The problem is after creating rule mywebsite.com/api/* with following settings: Browser Cache TTL: 2 days, Always Online: On, Cache Level: Cache Everything, Edge Cache TTL: 2 days
I still get OkHttp: cf-cache-status: DYNAMIC for that url.

Any help on that one? Do i need to wait couple hours for CF cache to start working?

Is that Page Rule #1? It’s possible you have an earlier rule that already matches this URL.

I do, added three just to make sure one of them works:

1

> *mywebsite.com/api/*

Browser Cache TTL: 2 days, Always Online: On, Cache Level: Cache Everything On

2 mywebsite.com/api//queryfeed.php
Browser Cache TTL: 2 days, Cache Level: Cache Everything On

3 *mywebsite.com/api/*
Browser Cache TTL: 2 days, Always Online: On, Cache Level: Cache Everything, Edge Cache TTL: 2 days

Which one shall i leave? Maybe its the slider next to rule showing GREEN ON but that actually means rule is off?

Green means it’s live.

#1 will trigger before the others, so 2 and 3 won’t happen. #3 is also unnecessary because #2 will match HTTP or HTTPS.

#1 doesn’t have Edge Cache TTL set. So if you disable #1 and #2, it should work.

EDIT: If there’s a query string after the .php, I don’t think this rule will match. Putting * on the end might help also.

There’s still no Edge Cache TTL in that one.

Unfortunately still getting DYNAMIC:

2020-03-22 21:46:13.562 22395-25545/com.vinwap.glitter D/OkHttp: <-- 200 https://vinwap.co.uk/glitter/queryfeed.php (1129ms)
2020-03-22 21:46:13.562 22395-25545/com.vinwap.glitter D/OkHttp: date: Sun, 22 Mar 2020 20:46:12 GMT
2020-03-22 21:46:13.562 22395-25545/com.vinwap.glitter D/OkHttp: content-type: text/html; charset=UTF-8
2020-03-22 21:46:13.562 22395-25545/com.vinwap.glitter D/OkHttp: set-cookie: __cfduid=dde2ec26d77650e518de9ce1c264723331584909971; expires=Tue, 21-Apr-20 20:46:11 GMT; path=/; domain=.vinwap.co.uk; HttpOnly; SameSite=Lax
2020-03-22 21:46:13.562 22395-25545/com.vinwap.glitter D/OkHttp: vary: Accept-Encoding
2020-03-22 21:46:13.562 22395-25545/com.vinwap.glitter D/OkHttp: cf-cache-status: DYNAMIC
2020-03-22 21:46:13.562 22395-25545/com.vinwap.glitter D/OkHttp: expect-ct: max-age=604800, report-uri=“https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct
2020-03-22 21:46:13.562 22395-25545/com.vinwap.glitter D/OkHttp: server: cloudflare
2020-03-22 21:46:13.562 22395-25545/com.vinwap.glitter D/OkHttp: cf-ray: 5782c2bbef58c683-MAD

That looks better.

Interesting…im trying via mobile app but dont thinkt that shoud make a difference?

tried now on my desktop browser via https://httpstatus.io/ and got HIT. will try browser on the phone

First try will be a MISS. It might even take a few before you’d hit the same cache twice and get a HIT.

on the same WIFI when i try via desktop or mobile browser i get HIT, but when trying via app I keep getting DYNAMIC… it should not make a difference on the client right?

It shouldn’t matter. Does the app do any type of caching? Can you try the app on a different device? Can you watch the server log to see what the app is actually hitting?

No the app is using standard http client but… its requesting it in POST not GET since it was sending some data limiter is POST a problem?

Seem like that is the problem. Just tried POST vs GET request and GET is ok with MISS and HITT but post always returns DYNAMIC. But that means i will have to update the mobile app to perform Get request instead of Post

Oh…yeah. POST kills all the fun. A POST should hit the server, as the server is supposed to do something with the POST data.

Exactly…and I imagine there’s now way to get around this without updating the app?

There’s a chance you could create a Worker that would change the POST to a GET, but Workers starts at $5/month, and cost even more if they’re getting tens of millions hits per month.