A databaseless approach for storing some data in PHP

I am new to PHP but not programming at all. I want to save some data that I retrieve from a web service, but I don't think I want to create a database for this. Firstly, the data will be updated quite often, and its size is always less than 1 MB. What is the best, fastest, but most efficient approach in PHP on Apache? Note. I use a hosting provider, so I do not prefer custom installations. Maybe singleton? Thanks

+4
source share
7 answers

Use the database. Otherwise, you are stuck in serializing the file. But for this you need to implement concurrency controls.

Save time and energy and use the database.

+4
source

I think the question will be, how long will the data be stored? If you save the data until it is replaced or longer than one user session, I personally think that the database is the ideal solution - it is very effective in quickly changing and retrieving data.

If data is saved for only one user session, you can use PHP sessions to store the data as an array.

Another alternative is to save the data in a file. However, this can be much less efficient when retrieving small amounts of data.

+1
source

Try using a flat file. Unless you need to make any fancy requests, that is.

0
source

An obvious alternative to the database is file storage. PHP can read and write old old files; see fopen (), fread (), fwrite (), and then some. You will need to specify the folder on the server (except for the public_html space) for the files (s) and draw up a naming scheme and format.

0
source

You can use the cloud service (Amazon, Google ...). But, besides the fact that your application is more complete and fragile, and you are more hip, I do not see any benefit from using a normal db or a flat file.

0
source

You can save arrays in a text file, serialize .

Sort of

$fh = fopen("db.txt", "w"); fwrite($fh, serialize(array("field"=>"data")); fclose($fh); 

Get it again using fread and mode "r", and then using the unserialize method.

 $fh = fopen("db.txt", "r"); $data = unserialize(fread($fh)); fclose($fh); 

And then manage your data in an array.

0
source

You can store your data in xml files and use simplexml to load and manage data, for example:

$ xml = simplexml_load_file ("test.xml");

Then you can have a list of nodes that you have defined and do your things. For more information, you can check the following:

SimpleXML Tutorial

0
source

Source: https://habr.com/ru/post/1341335/