I
I
Ivan Noname2018-06-04 06:42:27
PHP
Ivan Noname, 2018-06-04 06:42:27

How not to exceed the execution time of a PHP script?

You need to parse 50 web pages from PHP using curl. I'm afraid to exceed the script execution time. Sorry for the stupid question, but what to do in this case? Make a separate script and call it 50 times, if so, how to call it, via include?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stalker_RED, 2018-06-04
@wbsr

A table is made with tasks, where the address of the page to be downloaded is written. Also status, date, pid and number of attempts.
Child processes are launched php.net/manual/ru/function.pcntl-fork.php
They take the back ones from the table, put the status "in progress" and write the start time and pid.
If everything is successful, they write the status "ready" and complete the work.
If an error - write the corresponding status.
It also runs another script that checks all of these statuses and dates. If there was an error, and some time has passed, you can try again until the repetition counter reaches a certain value.
If the status "in progress" hangs for too long, one of the parsers may be stuck, and you need to click on its PID and restart it.
Thus, it is possible to process not only 50 addresses, but also 50,000, for example.
And yes, it looks like we are inventing something between guzzle and gearman here . You can take it ready.

P
profesor08, 2018-06-04
@profesor08

localhost:3000/?page=1
In script check $_GET["page"]

L
Lander, 2018-06-04
@usdglander

Are you going to run the parser through the web server? IMHO not a good idea. Launch via console. There, immediately along the way, it will be possible to display additional information about the process.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question