WAMP and pcntl_fork

后端 未结 3 1354
情歌与酒
情歌与酒 2020-12-31 22:03

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

相关标签:
3条回答
  • 2020-12-31 22:08

    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

    0 讨论(0)
  • 2020-12-31 22:20

    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;
       }
    }
    
    0 讨论(0)
  • 2020-12-31 22:26

    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:

    0 讨论(0)
提交回复
热议问题