+2 votes
by
Good afternoon, I need to contact a service via API and get quotes updates from the stock market every 3 seconds and write the result to the database in wordpress. Found a number of ready-made functions in google, but the problem is that the page takes 5-10 minutes to load, how to organize such a functionality?
by
once every 3 seconds and 5-10 minutes somehow doesn't add up.
by
Interesting site, that the page takes 10 minutes to load. The optimal variant - to set up a cron to receive quotes, and then just reload the page pulling up new data. But with such a large load need to deal
by
Would once a minute satisfy the father of Russian democracy?
by
Well, that's what I mean, the page took a very long time to load, the result was, but after a very long time

6 Answers

+2 votes
by
If you need to send a request every 3 seconds, then the best option would be this:
1. Install supervisord , configure its config and configure the config of the php script to run (there is nothing complicated about this, there are instructions on the Internet)
2. The php script itself will consist of an infinite while loop, at the beginning of which you will have a delay of 3 seconds:
while (true){
sleep(3);
// do some cool (or not) stuff
}
3. Run the supervisor and it's done) What's the plus side of this approach:
1. The while (true) loop will never end and will execute your code every N seconds.
2. The supervisor demonetizes your script, and it essentially becomes a service instead of just a php script
3. In the supervisor configuration for your script you can specify the parameter autorestart=true, and in case the script crashes, the supervisor will restart it without your participation (in case the host you are aping to crashes for a while)
by
FanatPHP I do not want to analyze the ability of the author of the question, I just pointed out the direction where you need to dig. If he wants, he will figure it out. For it's really not difficult (concerning the launching of the script once every 3 seconds, without regard to the consequences), you only need to spend some time reading the documentation for the tool and related articles.
+2 votes
by
Running the script via the CLI on the cron
by
Sergey Shilov ,
sleep; to help
by
Can you show me an example?
0 votes
by
Wouldn't it be better to use AJAX for this purpose?
by
With Ajax I will already output quotes from the database at the front
0 votes
by
From the browser every 3 seconds you send a request to your server, and on the server side your php-script will have to get the data from the API, write them into the database and send the result to the browser. It makes sense to limit the frequency of requests to the API, for example, if since the last request was less than a second, then take the result from the database without making any additional requests to the external API - this is to prevent you from being banned for too frequent requests.
by
Sergey Shilov What about the server, if the initiator will be the browser, which every 3 seconds by its request will make your php script work?

And for requests to the API were not sent too often (because on the site may be a few people), after each query write to the database its current time to the nearest second and the next time you just check whether it was 3 seconds.

What else do you need? Do you need them to write you a code as well? You can, of course, but that would be a paid order.
by
That's what I'm doing and I'm trying to ask - how on the server to perform a function once every 3 seconds
0 votes
by
#!/bin/bash
i=0

while [ $i -lt 6 ]; do
/run/your/command &
sleep 10
i=$(( i + 1 ))
done
0 votes
by
Ask the owner of the site about the availability of the ARI
...