WAMP and pcntl_fork

自作多情 提交于 2019-11-29 14:42:30

问题


Is there a way to make pcntl_fork work in WAMP? I need to develop a forking solution and test it locally.


回答1:


No, it's not possible. The PCNTL extension requires *nix platforms.

Now, with that said, what are you trying to do, and can you solve it without forking...?

Edit: Some alternatives to launching background processes:

  • Unix/Linux:

    exec('nohup php yourscript.php > /dev/null 2>&1 &');
    
  • Windows;

    $com = new Com('WScript.shell');
    $com->run('php yourscript.php', 10, false);
    

    For documentation on the arguments, see: http://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.85).aspx




回答2:


pseudo-code solution:

while (TRUE)
{
   $process_limit = get_process_limit();
   $process_count = get_process_count();

   if process count < process limit:
   {
      // get_row returns a row (as an array) from the DB that needs to be processed
      $row = get_row();
      if($row === array())
      {
         // Nothing to process; sleep
         sleep(2);
      }
      else
      {
         // Process row
         process_count(+1);
         process_row($row);
         process_count(-1);
      }

   }
   elseif process count === process limit
   {
      // Do not add to the process
      exit;
   }
   elseif process count > process limit
   {
      // Means the process limit was decreased
      // Terminate this process instance
      process_count(-1);
      exit;
   }
}



回答3:


This has already been answered but I thought I would add my 2p.

You can have pcntl-fork with php in windows using cygwin.

It's a real pain to install, but if like me you just want a php cli script to run, it's your best bet.

I got instructions from here:



来源:https://stackoverflow.com/questions/4879044/wamp-and-pcntl-fork

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!