public function testManager() { // Make sure PHP checks for signals, and handles them. declare (ticks=1); $test_text = "I'm doing something"; $fm = new Parallel\ForkManager(1); $logger = new Logger("test"); $testH = new Handler\TestHandler(); $logger->pushHandler($testH); $fm->setLogger($logger); $this->markTestIncomplete("Forking is hard to test. Todo, refactor to make fork a module so we can mock"); while ($fm->alive()) { // if ($fm->start('hello world')) { // continue; // } $logger->info($test_text); $fm->shutdown(); // $fm->stop(); } $has_announce = false; foreach ($testH->getRecords() as $record) { $message = $record['message']; if (preg_match('#Announcing#', $message)) { $has_announce = true; break; } } $this->assertTrue($has_announce, "FM Never announced a thread"); $this->assertTrue($testH->hasInfo($test_text), "FM never got to the fork body"); }
/** * Appologies for the commented code. * I would like to restore this functionality eventually. * this is supposed to verify that ticks is a small enough number, as required * by pnctl to fork and manage signals but that static var manipulation doesn't * work from PHP7 so we'll disable for now */ private function setup_ticks() { $tick_f = function () { ForkManager::confirmTicks(); }; register_tick_function($tick_f); // This is a short NOP+microsleep, just to // give verify_declare_ticks() a change to verify. $i = 0; $i++; $i++; $i++; time_nanosleep(0, 5000); if (self::$have_ticks) { unregister_tick_function($tick_f); } else { die("FM requires a 'declare(ticks=1);' in the calling code.\n"); } }