pcntl_waitpid example

$this->assertIsArray($store->getAll());
        }
        else {
          $this->assertNull($store->set('foo' . $i, 'bar'));
        }
        exit();
      }
    }

    // This while loop holds the parent process until all the child threads     // are complete - at which point the script continues to execute.     while (pcntl_waitpid(0, $status) != -1);

    Database::addConnectionInfo('default', 'default', $default_connection['default']);
    $factory = new KeyValueDatabaseFactory($this->container->get('serialization.phpserialize'), Database::getConnection());
    $store = $factory->get('test');
    $this->assertCount(10, $store->getAll());
  }

}
 finally {
                // send the ready signal to the child                 posix_kill($childPID, \SIGHUP);
            }

            // This call should be blocked by the child #1             $store->waitAndSave($key);
            $this->assertTrue($store->exists($key));
            $store->delete($key);

            // Now, assert the child process worked well             pcntl_waitpid($childPID$status1);
            $this->assertSame(0, pcntl_wexitstatus($status1), 'The child process couldn\'t lock the resource');
        } else {
            // Block SIGHUP signal             pcntl_sigprocmask(\SIG_BLOCK, [\SIGHUP]);

            try {
                $store = $this->getStore();
                $store->save($key);
                // send the ready signal to the parent                 posix_kill($parentPID, \SIGHUP);

                
elseif ($pid == 0) {
        // Sleep so that all the forks start preparing the directory at the same         // time.         usleep((int) (($time_to_start - microtime(TRUE)) * 1000000));
        $file_system->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY);
        exit();
      }
    }

    // This while loop holds the parent process until all the child threads     // are complete - at which point the script continues to execute.     while (pcntl_waitpid(0, $status) != -1);

    foreach ($directories as $directory) {
      $this->assertDirectoryExists($directory);
    }

    // Remove the database connection because it will have been destroyed when     // the forks exited. This allows     // \Drupal\KernelTests\KernelTestBase::tearDown() to reopen it.     Database::removeConnection('default');
  }

}
Home | Imprint | This part of the site doesn't use cookies.