D
D
Dmitry2016-09-22 17:59:10
Fonts
Dmitry, 2016-09-22 17:59:10

How to solve the problem less resource-intensive?

There is a constantly growing table of subscribers (currently more than 8000 entries).
Every 5 minutes, a CRON task is executed and the process of processing records for the last month is started (usually no more than 1000 records).
Processing involves calling a third party service API to get subscriber status (subscribed or pending confirmation) and, if the status is "active", the status in my table is also updated by a separate query. Also, in the absence of a user in the service list - re-adding through a request to the API of this service.
The question is how to optimize this process?
I repeat the data:
~ 1000 records from the database (one request for getting).
Cycle(in my case foreach) for that array.
Each iteration of the loop is a call to a third-party API, as well as updating the status of the subscriber in my database ( 1 request ), if it is "active" or a repeated request to the service API.
PHP 5.6, CodeIgniter 2, MySQL.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
Neron, 2016-09-09
Lordov @Nekto_Habr

Sans serifs - Cuprum
Serifs - who knows
Photo effect - I think this can be achieved through Halftone with subsequent toning

Y
Yuri, 2016-09-22
@another_dream

no way. the bottleneck is the call to the service.
Unless you can optimize saving to the database. mass updates in mysql are done by
insert into ... on duplicate key update ...
but I don't think this will speed up anything. 99% of the time your script is resting waiting for the response from the service.
to be convinced of it - make profiling. at least through microtime().

E
Evgeny Svirsky, 2016-09-22
@e_svirsky

And you can’t make a request to api by specifying 50 records, 100? If you can make such a Bulk Request, then there is only one way out - to make a bunch of requests and also process them in a bunch. Set statuses for sending and what is processed. The request can crash at any time. Don't forget when implementing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question