Jump to content

Long page operations blocks another WHMCS pages from loading


Recommended Posts

Hello, i came across very strange WHMCS behavior. For example i have installed WHMCS panel of version 7.1.2 on domain https://mywhmcs.com/ and also i have custom page long_query_page.php with simple code:

 

<?php

use WHMCS\ClientArea;
use WHMCS\Database\Capsule;

define('CLIENTAREA', true);

require __DIR__ . '/init.php';

$ca = new ClientArea();

print('Before long query');

long_query_function();

print('After long query');

 

long_query_function(); is function that's works about 30 seconds

 

After i requesting this page by http, like https://mywhmcs.com/long_query_page.php all of WHMCS pages in the same browser has blocked and not loaded until long_query_page.php is completed loading.

One more time. After i requesting page https://mywhmcs.com/long_query_page.php i can't open another WHMCS pages like https://mywhmcs.com/clientarea.php / https://mywhmcs.com/supporttickets.php in the same browser session (this requests are connected to web sever but waiting for data) until first request has completed.

It's looks like some mutex mechanism inside WHMCS is preventing of parallel pages loading in one browser session. :-\ is it right behavior or i am doing something wrong?

Link to comment
Share on other sites

I could be wrong but I think that it's pretty much normal and due to PHP sessions. It doesn't matter how hard you try to run multiple pages at the same time. PHP will lock session file and serve one page at a time. I don't know what you are trying to do but maybe you should use a different approach like making long_query_function(); a separate process, an ajax post or something that runs with a cron.

Edited by Kian
Link to comment
Share on other sites

If the PHP session must be writeable again, you need to resume the session after your long_query_function() with the PHP function session_start()

I have not tested it, but i can imagine that if session_write_close() is used within a hook, you may must resume the session afterwards so that WHMCS continues to work properly.
But note: to continue the existing session, you need the session id:

Quote

session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie.

 

Edited by string
Link to comment
Share on other sites

If you mean to do like this:

 

session_write_close();
long_query_function();
session_start();

 

It's will not help, because right after calling function session_write_close WHMCS loose session and user has log out till i start new session with session_start

I need a mechanism to process long_query_function after user do some action and save ability to manipulate with panel. So i see only two true ways to do this:

  • Move this functionality and call it with something like ajax request inside my module, but i think it still be problem with session blocking mechanism
  • Refactor all code to interacting through cron in background, but it's increases summary time of all operations (user submit action -> creating cron task -> waiting to cron starts and find task -> waiting for long_query_function ) and will cause complication of user notification mechanism (i need to add some "state" primitives to show it to user while task processed)

So maybe i loose something and there is another way?

Link to comment
Share on other sites

Like I have already said, I would send an ajax post and eventually show a spinner icon or a progress bar with % and details (eg. Calculating taxes... Done / Preparing missiles... Done). This way clients can see what is going on.

I would use the ID of the currently logged client to show him this "panel" even when he F5 or changes page.

Alternatively if you don't want to provide so many details, just send a separate curl() to your long_query_function() without waiting for answer.

If you need to prevent people from performing certain actions when the long_query_function() is still in progress, just place a boolean (0 = do what you want, 1 = you must wait) somewhere. It could be on a new table, column or a client custom field. If 1 die('Wait damn it!') else nothing.

Edited by Kian
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated