To describe my problem well i will firstly write few words about how my script work so far.
So there is a server which from time to time update XML under some address (lets say its (https://someaddress.com/feedback.xml). Then i have created a script which is being run one time daily ( using cron) that read the XML given and put new object in my database.
Now i want to get those objects in my another script ( it is important for me to create independent .php file which loads only newest object from feedback.xml. And here is the problem. I could load those values directly from database but this way I have a whole list of all records (I want only newest one) solution to this could be adding column in table which stores boolean value to New? question, but I cannot change in any way my database. I believe i could load those object to some array but then how can it be passed to another script? bellow i post method which i use to store records to database
$xmlstr = file_get_contents(url);
$xml = new SimpleXMLElement($xmlstr);
foreach ($xml->value as $a) {
//method to check if record exist
$rec= new Item($db);
//method to set values of obj
$rec->Store();
If your scripts run on the same server, then there are a number of different approaches that might work:-
(1) If your database already has a timestamp or a unique ID for the relevant row then you may be able to query the DB, order by one of these columns and then limit the results to 1 record.
(2) As well as writing the results to the database, you could also persist them in a local file and read from that each time (how big are these result sets?).
(3) Another option could be to use Memcached to persist the result set in memory so that your scripts remain decoupled but access to the information is very fast. If you haven’t used Memcached before then do take a look – it’s very good for just this sort of task and is simple to use.
If your scripts are running on different severs then (1) would work but the others would need further thought.