that's not really a thing you do in PHP, outside of frameworks like swoole/roadrunner. by nature it's a fire/execute/die shared-nothing model
Like others have mentioned, there is no such thing in PHP. Each request is handled individually from a blank slate and the context is destroyed when the request finishes.
Write to a database or file?
you mean $_SESSION? that was there since at least php4
And even that is limited to sharing data for a single user between requests. It's hard to accidentally share data between users.