Duplicate notification check triggers Error 508 (Loop detected)

I call AJAX to check the database if there is a new notif every 3 or 10 seconds with the same request from 4 different browsers at the same time. But at some point after the 100+ cycle, the server returns Error 508 (Loop Detected). This is a simple site, so I don’t think I need a VPS server.

I added the timestamp in SELECT as the query differential, placed unset, flush, mysqli_free_result, pause, mysqli_kill, mysqli_close, but the error still occurs. Input processes reached 20/20.

Script

var counter = 1; var notiftimer; $(document).ready(function() { ajax_loadnotifs(); }); function ajax_loadnotifs() { $.ajax({ type: "post", url: "service.php", dataType: "json", data: { action:'loadnotifs' }, success: function(data, textStatus, jqXHR){ $("div").append($("<p>").text(counter++ + ": succeeded")); notiftimer = setTimeout(function() { ajax_loadnotifs(); }, 3000); }, error: function(jqXHR, textStatus, errorThrown) { console.log(jqXHR.responseText); } }); } 

service.php

 $link = mysqli_connect('localhost', 'root', 'root', 'testdb'); $notifs = array(); $query = "SELECT id, message FROM notifs LIMIT 20"; if (!$temp_notifs = mysqli_query($link, $query)) { die(json_encode(array("errmsg" => "Selecting notifs."))); } while($notif = mysqli_fetch_assoc($temp_notifs)) { $notifs[] = $notif; } mysqli_close($link); echo json_encode($notifs); 

cPanel - Resource Usage Overview

cPanel - Resource Usage Overview

When input processes reach 20/20, I get error 508. How to maintain low server login processes? ( Tested using 4 different browsers, run them until the 100+ cycle on shared hosting is started. No problems on the local computer )

+7
ajax php hosting shared-hosting
source share
2 answers

It turns out that using https instead of http and AJAX 'get' instead of "post" prevents this error.

0
source share

What is considered an input process?

The "login process" is how many PHP scripts you run at a time.

Source: https://billing.stablehost.com/knowledgebase/186/What-is-considered-an-Entry-Processes.html

So the main problem that you learned about is that you end up running too many processes at once. There are several things you can do to solve the problem.

Option 1

Find a new website. This is perhaps the easiest, but also the most expensive, depending on what kind of financial agreement you have with your current host. Find one that does not have this restriction.

Option 2

Increase the time between ajax requests. Why do you need to request every 3 seconds? This is a very, very short time. What about 15 seconds? Or 30 seconds? Or hell, even 1 minute? Perhaps your users do not need to update their data as often as you think.

Option 3

Only make ajax call if current tab / window is in focus. There is no reason to poll for notifications if the user doesn’t even look at your page.

Check out Document.hasFocus() : https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus

Option 4

Implement a cache layer. If you feel that you still need to request data very, very often, then improve how quickly you retrieve this data. How to implement caching is up to you, but in some cases even using the write / read file can reduce the time and resources needed to complete the request.

After you receive notifications from the database, just save the JSON in a text file and receive subsequent repeated requests until the database data changes. See if performance improves.

If you want to focus even more on caching, you can look at options like Memcached ( https://en.wikipedia.org/wiki/Memcached ) or Redis ( https://en.wikipedia.org/wiki/Redis ).

Try combining several options for better performance!

+5
source share

All Articles