symfony/process · error · BadMethodCallException
Cannot serialize…
Error message
Cannot serialize Symfony\Component\Process\Pipes\WindowsPipes
What it means
WindowsPipes manages temporary files and open handles used for process I/O on Windows; these OS-level resources cannot be serialized. __serialize() deliberately throws BadMethodCallException to prevent it.
Solutions
- Close/finish the process before persisting anything
- Persist only serializable configuration and rebuild the Process on demand
- Exclude the Process/pipes property from your object's __serialize()/__sleep()
Example fix
// before
public function __serialize(): array { return ['process' => $this->process]; }
// after
public function __serialize(): array { return ['command' => $this->process->getCommandLine()]; } Defensive patterns
Strategy: type-guard
Validate before calling
if ($process->isRunning()) { throw new \LogicException('Cannot persist a running process'); } Type guard
function isSerializable(mixed $v): bool { try { serialize($v); return true; } catch (\Throwable) { return false; } } Try / catch
try { $data = serialize($obj); } catch (\BadMethodCallException $e) { $data = serialize($obj->toDescriptor()); } Prevention
- Exclude Process/pipes properties from serializable wrappers
- Cache process descriptors, not objects
- Test cache paths on Windows where pipes use temp files
When it happens
Trigger: serialize($process->getProcessPipes()) or serializing any object graph containing a live WindowsPipes instance (e.g. a running Process stored in cache/session).
Common situations: Caching a running Process on a Windows host, queueing a live Process object, or serialize-based debug logging.
Understand the failure class
Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.
Related errors
- Cannot serialize Symfony\Component\Process\Pipes\UnixPipes
- Cannot unserialize Symfony\Component\Process\Pipes\UnixPipes
- Cannot unserialize…
- TTY mode is not supported on Windows platform.
- Unable to kill the process
AI-assisted analysis of symfony/process@99b85026db (2026-09-14).
Data as JSON: /api/errors/4e5884c5cd653d42.
Report an issue: GitHub.
Appendix: source
Thrown at Pipes/WindowsPipes.php:92
flock($this->lockHandles[$pipe], \LOCK_UN);
fclose($this->lockHandles[$pipe]);
unset($this->lockHandles[$pipe]);
continue 2;
}
$this->fileHandles[$pipe] = $h;
$this->files[$pipe] = $file;
}
break;
}
restore_error_handler();
}
parent::__construct($input);
}
public function __serialize(): array
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}
public function __unserialize(array $data): void
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}
public function __destruct()
{
$this->close();
}
public function getDescriptors(): array
{
if (!$this->haveReadSupport) {
$nullstream = fopen('NUL', 'c');
return [View on GitHub (pinned to 99b85026db)