N
N
Nikolai Vasilchuk2010-10-08 19:53:42
PHP
Nikolai Vasilchuk, 2010-10-08 19:53:42

Recursive execution of PHP scripts?

Tell me, is it possible to run scripts recursively?
To make it clearer, let me give you an example.
Let there be a list of images (type id - filepath) that need to be processed. We call the a.php script with the id of the first image, like a.php?id=1. The script processes one image and calls itself, but with the id parameter of the next image, for example a.php?id=2, and then dies. Is it possible to implement such a system?

Answer the question

In order to leave comments, you need to log in

7 answer(s)
O
Oleg Matrozov, 2010-10-08
@Mear

In this question, the issue of running a certain task in php as a separate process was also raised:

C
Cheese, 2010-10-08
@Cheese

if "processing" does not mean their output, then something like this is sufficient:
//accessing a.php?id=0
//processing the image with id=0
$id=$_GET['id'];
$id++;
header("Location: site.ru/a.php?id= $id");

U
UJey, 2010-10-09
@UJey

Isn't CRON suitable for these purposes?
If you know the approximate processing time for one image, then it is better to set up the cron script execution every N minutes. The php script itself receives the next picture and starts processing, after which it marks this “task” as completed and ends.

U
UJey, 2010-10-09
@UJey

Here is another option, which, probably, will not help in all cases, but still I will give it ...
If applicable, an html page is made on which ajax request is sent to a php script on the server. After returning a successful response, we pause and send the request again. Etc.
This is how I did compiling a Sitemap for my site.
Requirements: loading the original html page in the browser
Limitation: maximum execution of the php script (in the server settings).

E
Eugene, 2010-10-08
@Nc_Soft

What are you doing with the images? I think you can do without perversions.
And to call php from the console with a parameter, you need to write this at the beginning of the script


if ($argc > 0) {
  for ($i=1; $i < $argc; $i++) {
    parse_str($argv[$i], $tmp);
    $_REQUEST = array_merge($_REQUEST, $tmp);
  }
}

and call
exec("/usr/bin/php /var/www/c.php id=1 > /dev/null &");

A
AFoST, 2010-10-08
@AFoST

Alternatively, at the end of the script execution with a.php?id=1, send a get/post http request to the script with a.php?id=2.

L
LoneCat, 2010-10-09
@LoneCat

Under Apache, you can use virtual , which executes Apache subrequests, but there is a tough attachment from Apache, for other servers you can emulate this functionality by making an external request (via curl, sockets, and at least file_get_contents), well, so that one script does not wait the completion of another one after the request is hard interrupted, and in the second set ignore_user_abort
And if it's not a secret, why do you need such cunning delights?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question