M
M
Max2017-03-04 14:59:29
PHP
Max, 2017-03-04 14:59:29

How to run multiple scripts in parallel from PHP under Windows Openserver?

Good afternoon!
You need to run N scripts once in a certain time interval, depending on the execution of the 1st script in the queue.
1st script is executed - determines how many scripts (threads) to run. Further, based on these data, you need to run N scripts with a slight delay.
How to do it? Redirect the 1st script to start threads with a variable or something like that, I don’t understand. Now I manually run all these streams through PHPSTORM and it's wildly inconvenient.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Max, 2017-10-29
@wtfowned

Decided as follows:
1. Script1 is launched by cron, works out and writes the result of its execution to a txt file (for logging and not only).
2. Script1 includes Script2, which launches the required number of scripts via a COM object (it was not possible to implement it in another way):

$com = new Com('WScript.shell');
$start_times = 10; // how much times to start
$go = 'script.php'; //scriptname
for ($i = 0; $i < $start_times; $i++) {
    $com->run('php C:\OpenServer\domains\scripts.loc\' . $go . ' 2>&1', 0, false);  //2ой параметр положительный чтобы консоль видимой была
}

As a result, the $start_times of the $go script threads are launched.
I also wrote a little stray from this that you can run an improved fragment of the previous code from any script and run the required number of threads from script options, parameter 1 - quantity, 2 - script name (specified in the array in advance), 3 - timing between runs.
exec("php C:\\OpenServer\\domains\\scripts.loc\\www\\exec.php 50 3 7 2>&1");

R
Ruslan, 2017-03-04
@mitrm

Look here or in similar solutions https://github.com/mitalcoi/yii2-cronjobs/blob/mas...

4
4iloveg, 2017-03-04
@4iloveg

There is a cron in the openserver.

M
MIK Ek, 2017-10-04
@MIKEk8

Perhaps popen will suit you.
php.net/manual/en/function.popen.php
Or if it's more confusing then proc_open .
php.net/manual/en/function.proc-open.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question