Hole wp multisite freeze while doing bulk(add_blog) or bulk(add_user_to_blog)

Hi, i have installed a wp multisite with about 600 Blogs.
Therefor I created a Backend-Plugin to set the user-roles for multiple blogs with one-click.
Within this Plugin i use the wp-core functions add_user_to_blog and remove_user_from_blog (they use the switch_to_blog-function itself)... so if i change the role for 50+ Blogs at once, the script needs about 20-30 seconds to finish my request.

Now the Problem is, that in this 20-30 seconds the script needs the hole wp Multisite is frozen. So there is no other request (frontend and backend) possible. After my script finished, the other requests finish too.

The Server should have no Problem, cause i have an Intel QuadCore with Hyperthreading (8 processors) and 32 GB RAM only for this project. I use a nginx/php-fpm/mysql - Setup.
While the wordpress is frozen, its possible to search the database with the same username wordpress is using via phpmyadmin and its also possible to do php-requests on the same domain outside the wordpress-logic...

So for me it looks like that wordpress freeze the site on purpose. May anyone help me to solve my problem, cause i think there is no need to freeze the frontend if I change some roles from users.

  • loremipsum
    • WPMU DEV Initiate

    Hi Paul,

    the scripts are finishing correctly.. so there is no problem with memory limit or upload time...
    i try another way to explain my problem:
    First: 1 start a request in the backend which runs i.e. through 100 blogs to set there a user-role... foreach (blogs as blog) -> add_user_to_blog();
    This request needs around 30-40 seconds...

    within this 30-40 seconds, every second request i make within the wordpress -logic (i.e. visit dashboard, visit frontend-startpage, or something else)... is frozen... so i send the request via browser and the browser is loading as long as the first request is finished... after that every other request in the wordpress-logic is also finishing correctly...

    perhaps this discribed it better than before :slight_smile:

  • loremipsum
    • WPMU DEV Initiate

    omg.. now it becomes really strange...

    i tried to add a sleep(15) to the themes category.php and now it became really strange...
    the category-request tooks as assumed about 15 seconds, but in this time i have the same issue, the other pages are frozen as long as the first request need...

    now i tried the same thing to a normal wordpress-install on an other maschine, no problem... same try on another maschine with an wordpress-multisite with the standard-theme... also no problem....

    is really strange, cause i never had a problem like this with wordpress since now... perhaps after all its still a problem with my nginx/php-fpm/mysql config which i thought it should not...
    but its late today, i will check this tomorrow

  • loremipsum
    • WPMU DEV Initiate

    ok... next try.. if i add the sleep in the /root/index.php (called with a GET-Variable) and tried to call some more requests without the Get-Variable (without sleep), then there is no problem with the loading...
    so it seems that some plugin is also calling a function which is locked by wordpress.

    could it be that switch_to_blog is a function that is locking wordpress, cause i need this function in the frontend too?

  • loremipsum
    • WPMU DEV Initiate

    so now i found the problem... not wordpress core was something locking, but an plugin which loaded a config-file within the __construct and locked it with flock(); until the __deconstruct was called...

    It was so strange for me, cause it was so unusual for wordpress acting like this...

    thanks you everyone who tried to help me solving my problem :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.