Call to undefined function flock() in …/html/wp-admin/includes/misc.php:182

Hi!

I tried to open the page “/wp-admin/options-permalink.php” on my site, but it wouldn’t load because of a critical error. It turns out the problem is as follows (from debug.log) :

PHP Fatal error: Uncaught Error: Call to undefined function flock() in /www/.../html/wp-admin/includes/misc.php:182
Stack trace:
#0 /www/.../html/wp-admin/includes/misc.php(285): insert_with_markers()
#1 /www/.../html/wp-includes/class-wp-rewrite.php(1899): save_mod_rewrite_rules()
#2 /www/.../html/wp-includes/rewrite.php(282): WP_Rewrite->flush_rules()
#3 /www/.../html/wp-admin/options-permalink.php(212): flush_rewrite_rules()
#4 {main}
thrown in /www/.../html/wp-admin/includes/misc.php on line 182

Once I comment out the two lines in misc.php that use the function flock(), the page (options-permalink.php) opens just fine. But I realize this might not be an optimal solution or might even raise other issues!

So my question is – how come a native PHP function flock() is undefined, and how can I fix this in a better way? On previous lines in misc.php other PHP functions are used, such as fopen(), and there’s no error. I have PHP 8.1 and the latest WP version (6.5.2).

I don’t know if this is related to updating to the new WP version or not, as I haven’t tried opening the page in question earlier. But today, while debugging, I disabled the Elementor plugin and tried to re-enable it – that wouldn’t happen because the plugin would cause an error, but once I commented out those lines in misc.php I could enable Elementor again. Such a problem hasn’t happened before with plugins, so I’m guessing this might have something to do with the update.

(Originally navigated to options-permalink.php to flush permalinks because the Site Health suggested that, saying “The authorization header is missing”, which I guess is a whole different issue I have no idea about 😀 The site was originally made by someone else and I have gradually learned WP stuff myself to do changes to it.)

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer