Query database or json file

0

Good morning.

I will write as specific as possible.

I want to make a notification system which will inform users that an application has been answered. I use PHP without framework and Mysql.

I can create a table to save and update the current number of requests of each user, that each time a request is answered the number associated with the number of requests of that user increase and when consulting the database through ajax opt the number to be compared with a count of the user generated request tables.

The other option is to create a file json obviously not consult the database, the idea of this is that when you are responding requests see and write the file json associated with this user.

The file would have an array that contains the user name, current number of requests, new quantity, etc. When the user clicks on the notifications icon, the file is updated and the number of new requests will be the same as the current one and will not notify him until the process is repeated.

Finally my question is that it would be more efficient?

Note: The system currently has more than 300 simultaneous users connected, I also know how to do the two options although I am open to other alternatives.

Note2: It is a system that is in a closed network so I can not depend on external services.

    
asked by Albert Hidalgo 06.01.2018 в 00:07
source

2 answers

2

Hello! It is not good practice to directly manipulate JSON files or store data in them, any error could make you lose all that data.

If you want it to be ultra dynamic (and without spending space on your server) you could take a look at Firebase ( link ), but It has its learning curve. Firebase is destined to this type of problematic.

If you need something more known, I would put in the same request table a boolean column "seen", which is False by default and goes to True with Ajax when a user sees the request. I would not make a specific table for that, it seems redundant and harder to climb. To show the number of notifications in the WHERE, you set the user_id to be the user's id and to be False.

I hope I have understood your problem well and that my answer will be useful, Greetings!

    
answered by 06.01.2018 / 00:40
source
1

If you already have the MySQL database working, use it better for all your tasks, in fact I mention that from version 5.7 of MySQL you can store JSON as you would in a traditional file; all you need is to create the field that will store this info as follows:

CREATE TABLE solicitudes( 
   id INT,
   solicitud_respondida JSON NOT NULL,
   nombre_solicitud VARCHAR(100) NOT NULL,
   pk_solicitudes PRIMARY KEY(id)
);

If you realize we continue with the same classic structure to create tables with SQL language but you can add JSON structure as the notes I hope it serves you.

    
answered by 19.02.2018 в 03:17