Jump to content

Hooks: Delays on My Product page


pRieStaKos

Recommended Posts

Hello,

I recently redesigned my template and I included hooks that returns information about service's server status (status / uptime).

When a client has above 50 services (active), the page takes a lot of time to load. I tested and it takes above 60 seconds (avg) only to load the page, from any other page inside WHMCS.

I checked and I know that my hooks are slowing down the page, but I need to decrease the loading time, or somehow change the page loading flow.
If I could make the page loads and load the hooks after, so the visitor can see that the page is loading, but the table list takes time to fully rendered. 

Any suggestions ?

Thank you in advance.

Edited by pRieStaKos
Link to comment
Share on other sites

27 minutes ago, pRieStaKos said:

Any suggestions ?

I have 2 suggestions:

  • Cache the server status, you can use the AfterCronJob hook to refresh the cache every 5 minutes. AfterCronJob is executed each 5 minutes by default. You could also create your own cronjob which is executed more often. But you should take care that the executions do not overlap. For example with a lock file or an entry in the database like "if is_running = 1, then dont execute".
  • To get a real-time status, get the server status via an AJAX request. In that case you will also want to update your hook to not block the PHP session.
  • curl_multi, setting reasonable timeouts and reusing the same curl handle (if you do multiple requests to the same server) can help reducing the query time.

Personally I would prefer the first suggestion as it is less prone to errors. 

Edited by string
wrong link
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