Skip to content

Above and Beyond: Avoiding PHP Timeout and Memory Limit Errors with Ajax

Unlike some other programming languages, PHP shuts down completely the moment it stops processing a specific request.

Different programming languages have very different lifespans. Your computer’s operating system, for example, runs continuously—executing tasks, consuming memory, and so on—as long as your computer’s on. Imagine if your computer was designed to shut off and boot back up in between each keypress on your keyboard!

As insane as that sounds (and would be for an operating system), it’s pretty much how PHP works. PHP was designed specifically to be run on web servers, handling one-off requests from numerous clients. Since a server talks to many (even millions of) clients at once, it’s best to free up all that client’s resources the moment its request is complete. As a result, PHP shuts down completely the moment it stops processing a specific request.

So each new request made to a PHP codebase requires PHP to rebuild itself from scratch—which is why, for example, your WordPress site builds itself, from init on up, each and every time someone wants to view a new post on your blog. It’s a bit like a hotel rebuilding itself every time there’s a visitor, but it turns out to be the best way to serve web traffic.

PHP Can’t Run Forever

PHP turns out to be quite bad at handling long-running processes.

Yay! 🎉 You made it to the end of the article!
Fred Meyer
Share:

0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!