M
M
MOLOD2021-03-17 20:53:02
PHP
MOLOD, 2021-03-17 20:53:02

How to accept only up-to-date data via API in PHP without a database?

Hello everyone, I'm learning PHP and so far at the stage of learning OOP, but for now I'm practicing procedurally.
Faced with the banal as it may seem, I accept the data of the service via the API and send it to another service, but I need to send only unique data, let's say I have news, and it was already sent when the script was running, how can I build the logic so that the script does not repeat I sent this news, I don’t know what to attach to, I can only attach to the date and time, but somehow I didn’t know how to use it correctly.
It would be possible, of course, through id, but I don’t want to fasten my database ..

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
yosiaproger, 2021-03-17
@TOOMOLOD

Simulate a database, for example, with some file. There to write the serialized data.

R
rPman, 2021-03-17
@rPman

where you have to store what you have already sent, you can not start identifiers, but calculate the hash from the key parameters by which you determine the uniqueness (header or all content), take this hash and store it as an identifier.
you need a key-value database, if there is not enough data and it fits into memory as an array $index[$hash]=true then store it in a file in a serialized form var_export/serialize/json_encode or even 1 line per entry - read array_flip(file ('file name'))
ps take sqlite, you can't find such a simple, convenient and unpretentious database, it is implemented in a file, it does not require anything for administration, it works everywhere...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question