S
S
SemenDemon2016-03-20 02:22:38
PHP
SemenDemon, 2016-03-20 02:22:38

Possible parallel execution of php?

task
1) get the time of the previous request
2) store the start time of the current request
3) execute the request (2-10 seconds download via http)

$id = 0
       $time = $this->cache->get('vk_obj_start_time'.$id);
        echo '<br>loaded_time'.$time. ' '. date('d.m.Y H:i:s',$time);
        $parameters = array(
            'q' => $this->search_word[$id],
            'count' => 100,
            'start_time'=> $time
        );
        echo '<br>now '.time();
        $this->cache->save('vk_obj_start_time'.$id, time(), 30000);
        return file_get_contents($url);;

instead of the expected $time=0 (in the cache it is 0, replaced by saving in the database - the same thing)
it turns out $time = current time +-(1-2) seconds always different
file_get_contents execution time 2-10 seconds
for some reason $this is executed first ->cache->save and then only $this->cache->get
function does not work in a loop, checked
you remove file_get_contents everything is fine ( $time=0 the first time, the second time $time={last execution time} you
remove $this->cache->save all good $time=0 always

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
SemenDemon, 2016-06-12
@SemenDemon

solution: requests to the script were made through google chrome (browser preloading)
localhost/cron/vk/load_real/2
localhost/cron/vk/load_real/3
localhost/cron/vk/load_real/4
when you manually change the id, chrome loads the page preview again before the transition.
that is:
1) in the address bar was localhost/cron/vk/load_real/2
2) delete 2 (press backspace) localhost/cron/vk/load_real
3) write 3 (do not press enter yet) localhost/cron/vk/load_real /3
and chrome infection has already loaded the page localhost/cron/vk/load_real/3
4) press enter (to get the page localhost/cron/vk/load_real/3)
As a result, I get a downed time counter. the script is processed sequentially as required. and as a result I see the page time () + 1 and a false feeling of parallel execution is created.

N
nick23, 2016-03-24
@nick23

Perhaps this library will be useful:
ko-process
If you need exactly parallel execution

J
justpusher, 2016-03-26
@justpusher

I advise you to add verbose logging to the file in several places in your code. Log microtime, process id, current request ID and variable values. This will help you figure out what's going on.
PS The title of the question is extremely unfortunate.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question