PNewCode Posted September 16, 2023 Share Posted September 16, 2023 (edited) Hello everyone. I have a chat that I made. The problem is that it crashes every 10-50 min (depending on how many people are in there). I know having it refresh with ajax every second isn't the smartest way but could that be the reason? The error is "out of memory". Everything that I'm reading says it's a browser thing but every single viewer is getting the exact same thing on all browsers (sometimes worded a little different on some browsers) Chrome, Firefox, Edge, Android default, and Safari all do this. I don't know a thing about websockets, but it looks like this could be preventing that. Is that true? I cringe at having to learn all that stuff with Node.js and stuff it looks like this will require. So I'm hoping maybe there's a diffent solution Note: I didn't include any code here because it's a general question really. And my chat is made up of 4 different files for customization and stuff. It is using php mysql database and ajax every 1.5 second to load the chat to prevent lag from entering a post and appearing in the chat window. All advice is appreciated. Note 2: If you're wondering "Why are you using a database and ajax" the answer is, because thats at the extent that I've learned so far. Edit: I forgot to add that there are no errors showing or warnings in the console or logs, not even suggestions Edited September 16, 2023 by PNewCode Quote Link to comment https://forums.phpfreaks.com/topic/317292-php-and-ajax-websockets-vs-ajax/ Share on other sites More sharing options...
mac_gyver Posted September 16, 2023 Share Posted September 16, 2023 where is the error being generated at or seen at? i suspect is it a php error message being displayed in the 'chat' output? the reason it may appear differently is because it contains html markup, which may or may not get rendered by the browser. out of memory errors as usually caused by logic that either has an initial condition problem, where an assumption being made isn't satisfied, or a loop that runs forever and keeps adding data until all memory is consumed, without removing older data. Quote Link to comment https://forums.phpfreaks.com/topic/317292-php-and-ajax-websockets-vs-ajax/#findComment-1611905 Share on other sites More sharing options...
PNewCode Posted September 16, 2023 Author Share Posted September 16, 2023 @mac_gyver it takes over the whole screen with the "out of memory click here to refresh" and if you refresh then it loads it all again just fine, but the viewers are aggravated. No other error is showing on screen, log, or console. Based on youre reply I'm thinking it's probably from the ajax call loading the page every 1.5 seconds Quote Link to comment https://forums.phpfreaks.com/topic/317292-php-and-ajax-websockets-vs-ajax/#findComment-1611906 Share on other sites More sharing options...
PNewCode Posted September 16, 2023 Author Share Posted September 16, 2023 Quote Link to comment https://forums.phpfreaks.com/topic/317292-php-and-ajax-websockets-vs-ajax/#findComment-1611907 Share on other sites More sharing options...
maxxd Posted September 16, 2023 Share Posted September 16, 2023 Making an ajax call every 1-2 seconds wouldn't cause what you're seeing, but if you're appending the full dataset into a JavaScript array on every ajax return that could be it. If you initialize the page with a JavaScript array containing all messages and then append all messages again every 1-2 seconds, that array is going to grow exponentially very quickly and an out of memory error would be a distinct possibility. Make sure you're returning new messages only from the PHP so only those get appended to the array or object. Quote Link to comment https://forums.phpfreaks.com/topic/317292-php-and-ajax-websockets-vs-ajax/#findComment-1611909 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.