I've written some Perl code using FCGI managed by
mod_fcgid, in which I constructed my own request loop and application pre-loader. (And complained about the way mod_fcgid is set up, since it doesn't pre-fork fastcgi children—whenever concurrency is exceeded, starting from zero after a fresh startup, someone has to wait for the world to load just like the bad old CGI days.)
I've written plenty of PHP as well, where you get to generate a response in response to routing once the server environment gets around to delivering the request to you. The only things that may persist from request to request are allocated on the C level, not by the PHP script directly: most famously, opcode caches and persistent database connections.