I decided to run the parser in several processes. To do this, first run the program in the console like this: "php parse.php m 4". After that, the program considers how many goods it is necessary to parse and starts 4 daemon with parameters offset and limit:

exec($path_php.' -q parse.php p '.$offset.' '.$limit.' '.$i.' > logs\daemon_'.$i.'.log 2>&1 &'); 

According to the documentation, it is necessary for exec not to hang, so that it does not display anything on the screen, so I saved it to the log, as you can see. In my program I use the print operator. How to make exec not hang? That started the demons and let them work in the background itself.

  • So what's the problem? You wrote ... > log 2>&1 & and your php is still waiting for completion? Or what? And print in the daemon or in the program that launches the daemon? - BOPOH
  • print in the daemon. Yes, php is waiting for the end, moreover, the log is written only when the entire program is executed, and before that it is not written anywhere. Strange somehow. That is, I have a cycle of writing a piece there in a log that is sparseno, and for some reason he waits until the whole cycle passes and only then writes the whole pack to the log - iproger

1 answer 1

It turned out the whole thing is that I did it in Windows. I threw scripts on a virtual machine on * nix system, in my case Ubuntu - everything worked as it should! Thank!)
And on windows I never managed to run in the background, start /B does not help :) But nothing, the virtual is always at hand)