Can switching to polling data from a SQL database instead of a file in a chat application lead to improved performance?

Currently developing a chat application and considering using a SQL database for it.

The challenge is that I've come across conflicting information online regarding the performance of using a DB versus a regular file (such as Text or JSON). User experience is my priority when creating web applications.

While SQL would allow me to add more features and enhance the app, if it leads to noticeable lag for users, then it's not ideal.

I plan to continuously poll the server with AJAX and PHP to monitor the file/DB for new messages and contact requests.

The chat application will not be just 1-to-1, but will have rooms where multiple users can participate. Users can also initiate private chats for one-on-one interactions.

So, should I go with a MySQL Database or a simpler TEXT/JSON/OTHER file in terms of performance?

Additionally, I prefer not to rely on third-party libraries or APIs due to past disappointments.

Answer №1

If you're interested in developing your own IRC clone, it's important to choose the right tools for the job.

One effective approach is to create a custom HTTP server that operates entirely in memory. By avoiding databases and constant file polling, you can efficiently handle incoming messages by looping through an in-memory list and distributing them to other users. To establish connections between browsers and servers, consider using "Comet" with web sockets for browsers that support this technology.

PHP may not be ideal for this type of project, as its functionality is primarily geared towards short, isolated requests. For a long-running process serving multiple clients in real time, languages like Python or Node.js might be better suited.

Answer №2

Storing chats in files can lead to a management nightmare, so I recommend using MySQL and Sockets instead of AJAX polling for better functionality and scalability.

Integrating socket-based chats with MySQL may not be well-documented, but I have successfully created a basic example which you can find here: https://github.com/andrefigueira/PHP-MySQL-Sockets-Chat

This example uses Ratchet () to create the chat server in PHP.

You can send chat messages to the database by sending the server JSON with user information (assuming you have user sessions set up).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to have a PHP variable embedded within an HTML link tag?

<?php $message = ' <a href="' . $link . '">here</a> '; ?> My goal is to include a clickable link in the $message variable for use in the mail() function. However, despite setting $link with the desired link string, it ...

Are there any tutorials available for creating complex web applications using Symfony2?

I am embarking on developing a sophisticated web application using Symfony 2, which involves managing 20 different database entities with many-to-many relationships. Although I have programming experience, I am relatively new to Symfony and object-oriente ...

Sending form data using Ajax

My concern is quite straightforward - I am using jquery and ajax to submit a form. When the button is clicked, the data gets sent to the database. The question is - if the user clicks the submit button twice, there will be two entries in the database. Ho ...

Experiencing difficulties while transitioning to MySQLi for updates

After spending some time delving into MySQLi, I am facing a challenge in updating a script with new functions. The script is utilized for a dynamic dropdown form that receives data through JS. To get a better idea of what I'm referring to, you can vie ...

Calling Ajax in JavaScript

Trying to fetch a value in JavaScript using an Ajax Call, The code being used is as follows: <script> var value = $.ajax({ type:"GET", url:"get_result.php", data:"{'abc':" + $abc + "}", }); alert(val ...

Symfony allows for unique field validation for one-to-many relationships

My Request entity contains multiple Interventions structured as follows: Request.php /** * @ORM\OneToMany(targetEntity=Intervention::class, mappedBy="request") * @Assert\Count(min=1, max=3) * @Assert\Valid ...

Endless Scroll Feature in Javascript

A brief tale: I am in search of a way to extract data from a website that features infinite scroll without actually implementing the infinite scroll feature myself. My plan is to create a script that will auto-scroll the page from the browser console, wai ...

Attempting to replicate an unreplicable object belonging to the mysqli_result class

why do I keep getting this error message: A severe error has occurred: Attempting to clone an uncloneable object of mysqli_result class each time I attempt to use the clone function on a mysql query result: $result = mysqli_query($con, $query); $resu ...

Javascript function to deselect all items

One of my functions is designed to reset all checkbox values and then trigger an AJAX request. However, there are instances when the function initiates before the checkboxes have been unchecked. function clear() { $("#a").prop("checked", false); $("#b ...

A div containing a form, with the form being visually integrated within the div

Hi everyone, this is my first post here and I've tried to search extensively before asking this question. I've attempted to use the following examples without success: jquery submit form and then show results in an existing div Form submit ...

Guide to using Django's Ajax functionality for URL redirection

A current issue I am encountering is the inability to display the cartempty page when the item count reaches zero. Here is a snippet of the code: if request.is_ajax(): if request.POST.get('action') == 'remove': cart_item.delete ...

Implementing file uploads with Bootstrap, jQuery, and Laravel

Looking to incorporate the blueimp jquery file upload feature into my Laravel app. Check it out here: https://github.com/blueimp/jQuery-File-Upload The form is set up and working properly with the plugin, but facing issues with creating server-side script ...

The magnifying glass icon is missing from the autocomplete search feature

After creating an autocomplete search functionality that queries my mysql database, I encountered a slight issue. Here is the code snippet showcasing my implementation: <div class="search-bar"> <div class="ui-widget"> <input id="ski ...

Guard your website against Backdoor/PHP.C99Shell, also known as Trojan.Script.224490

Recently, my website fell victim to a trojan script infiltration. Someone maliciously inserted a file named "x76x09.php" or "config.php" into the root directory of my webspace. This file, with a size of 44287 bytes and an MD5 checksum of 8dd76fc074b717fcc ...

Need to authenticate an API request for uploading a file?

When creating Wave Framework, I placed a strong emphasis on the security measures for API requests. It was crucial to ensure that API requests could be made securely over HTTP while guarding against potential middle-man attacks, data tampering, and other v ...

PHP process encountered an issue loading the gettext module, causing it to be inaccessible

I have encountered a problem with the gettext module in PHP that remains unsolved despite trying various solutions. Every time I attempt to use the gettext module, I receive the following warning message: PHP Warning: PHP Startup: Unable to load dynamic ...

Having HWIOauthBundle version 0.3.*@dev installed on Symfony 2.3.4 resulted in encountering the common error message "No oauth code present in the request."

I'm hoping I haven't overlooked anything important. Following the instructions provided in this link, I have successfully installed HWIOauthBundle (along with FOSUserBundle): https://gist.github.com/danvbe/4476697 I copied code from the files t ...

How to manually trigger the ajaxLoader feature in Tabulator version 3.5

Currently, I am working with version 3.5 of Tabulator from . When populating the table using an ajax request, a "loading icon" is displayed during the loading process. Prior to executing the ajax request for Tabulator, I perform some preliminary check op ...

How to Retrieve JavaScript Array Data Using Ajax in a Wordpress Plugin and Store it in a PHP

function my_custom_js_action($value1, $value2) { ?> <script type="text/javascript" > jQuery(document).ready(function($) { var newData = { 'email': '<?php echo $value1?>', 'p ...

Removing a post through the integration of socket.io, MySQL, Node.js, and Express

Currently, I am working on creating a basic messaging app that enables users to add statuses and update them in real-time for everyone to see. The technologies I am using include socket.io, MySQL, Node.js, and Express. Users have the ability to send messa ...