linux işçi script / kuyruğu (php)

5 Cevap php

Ben şunları yapar ikili / script (php) gerekir.

Arka planda X'in n işlemini başlatmak ve numara işlemleri korumak.

An example: - n = 50 - initially 50 processes are started - a process exits - 49 are still running - so 1 should be started again.

Bu acil lütfen.

Teşekkürler! Michael

PS: Ben beni muhtemelen çok sevilmeyen yapar SV, aynı soruyu yayınlanmıştır. Ben biliyorum, ama yine de acil.

5 Cevap

Pseudocode:

for (i=1; i<=50; i++)
  myprocess
endfor

while true
  while ( $(ps --no-headers -C myprocess|wc -l) < 50 )
    myprocess
  endwhile
endwhile

Eğer php bu tercüme ve onun kusurlarını düzeltmek, sadece ne istediğinizi yapabilir.

Eğer bir PHP Daemon önce yaparak denediniz mi?

http://kevin.vanzonneveld.net/techblog/article/create%5Fdaemons%5Fin%5Fphp/

İşte / benim kütüphanede var Perl şey (ve hey, ben sadece o dilde bu anı çalışan bir şey vermek için PHP teçhizat bu kadar gitmiyorum, dürüst olalım. Sadece ben kopyalayabilirsiniz ne kullanıyorum ) yapıştırın.

#!/usr/bin/perl
use threads;
use Thread::Queue;

my @workers;
my $num_threads = shift;
my $dbname = shift;
my $queue = new Thread::Queue;

for (0..$num_threads-1) {
        $workers[$_] = new threads(\&worker);
                print "TEST!\n";
}

while ($_ = shift @ARGV) {
        $queue->enqueue($_);
}

sub worker() {
        while ($file = $queue->dequeue) {
                system ('./4parser.pl', $dbname, $file);
        }
}

for (0..$num_threads-1) { $queue->enqueue(undef); }
for (0..$num_threads-1) { $workers[$_]->join; }

Bu sistemler aramalardan biri bitirir zaman, o dequeing geçer. Ben hwy biliyorum Oh, ve lanet yaptım 0..$numthreads yerine, normal my $i = 0; $i < ... deyim, ama ben bu şekilde o zaman yaptım.

Can you use the crontab linux and write to a db or file the number of current process?. If DB, the advantage is that you can use to procedure and lock the table, and write the number of process.

Ama Backgroun için kullanmak ve gereken komut dosyası aramanın sonunda

# php-f pro.php &

Ben andres önerdi yöne gitmek istiyorum. Sadece pro.php dosyasının en üstünde böyle bir şey koymak ...

$this_file = __FILE__;
$final_count = 50;

$processes = `ps auwx | grep "php -f $this_file"`;
$processes = explode("\n", $processes);
if (count($processes)>$final_count+3) {
        exit;
}
//... Remaining code goes here