Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a restart() method on a Process #5452

Closed
boombatower opened this issue Sep 7, 2012 · 1 comment
Closed

Provide a restart() method on a Process #5452

boombatower opened this issue Sep 7, 2012 · 1 comment

Comments

@boombatower
Copy link
Contributor

I wrote my own Process class on top of proc_open() before I found the Process component of Symfony2. For my use-case I need to be able to easily restart process so my class provides a restart() method that works as follows.

<?php
public function restart()
{
  $process = clone $this;
  $process->run();
  return $process;
}

public function __clone()
{
  unset($this->resource);
  unset($this->pipes);
}

It make sense to create a new Process in order to preserve the status and pipes from the last one. I have a process manager that restarts processes when they crash.

Does something like this seem acceptable? If so I will create a pull request.

@schmittjoh
Copy link
Contributor

I think it's not so obvious that restart returns a new instance of Process instead of working on the instance that it was called on, but generally +1 for a restart command.

fabpot added a commit that referenced this issue Oct 4, 2012
This PR was squashed before being merged into the master branch (closes #5456).

Commits
-------

be62fcc [process] provide a restart method.

Discussion
----------

[process] provide a restart method.

Pull request for issue #5452.

Another possibility would be to allow for either run() or start() scenarios, but I am not sure that is terribly useful since restart() with a new process lends itself to restarting longer running services when they crash and you want the old process so you can inspect the logs and what not.

Otherwise, something like this might work, but doesn't allow for run() to return status code. Someone can get around that by getting manually on returned process.

```php
<?php
public function restart($method = 'start', $callback = null)
{
    if ($this->isRunning()) {
        throw new \RuntimeException('Process is already running');
    }

    if ($method != 'start' && $method != 'run') {
        throw new \RuntimeException('Method must be start or run');
    }

    $process = clone $this;
    $process->$method();
    return $process;
}
```

---------------------------------------------------------------------------

by pborreli at 2012-09-07T07:17:26Z

can you add some tests please ?
@fabpot fabpot closed this as completed Oct 4, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants