[PHP] Is there a pref setting governing caching of async form submissions?

Hello;

I am working on a project that submits form data asyncronously*.
I have to look over the results to figure out what needs to be corrected.
The results are in the form of file contents written by php code.
Sometime I make changes to the php code that should result in changes
to the file. Those changes would be visible by opening and reading the file
with my own eyes. But the file is not changed.

* 'ajax' submission

I figured out that the submissions are be cached somewhere and I have
to tell my browser to dump its cache so the revised php code will be
reread and the changes applied.

So it PHP caching form submissions"?

javascript its used to construct and submit the form data and I know
that it caches that type of data. That is usually solved by reloading
the page from the server. But that is not rereading the php code.

system: MAMP on Mac os Sequoia localhost
php vers 8.2.20, browser used to test; Firefox

Thank you for time and attention
JK

On 18/01/2025 20:13, JEFFRY KILLEN wrote:

So it PHP caching form submissions"?

No. PHP does not cache requests / responses in this manner.

The most likely source of caching is the browser itself. There are several ways you can avoid this:

1) Use POST or PUT submission method. In general, by default: GET requests may be cached, POST and PUT (and DELETE) requests are not cached.

2) Append a random value to the query string, which changes with each request. The current (unix) timestamp is a commonly used value since it will always be unique (at least for submission not made in the same second). eg: /form-endpoint?nocache=48738743593 (some client-side libraries, such as JQuery have an option that does this).

The server-side doesn't need to do anything with this value, but the fact that it's there makes the browser see each request as a different one from any previous request.

3) Use appropriate HTTP headers (eg. Cache-Control - see links below)

Further reading:

* HTTP caching - HTTP | MDN
* Cacheable - MDN Web Docs Glossary: Definitions of Web-related terms | MDN