diff --git a/src/FileTask.php b/src/FileTask.php index 9e568b5..680152e 100644 --- a/src/FileTask.php +++ b/src/FileTask.php @@ -4,10 +4,10 @@ class FileTask { - public string $file; + public string $file; - public function __construct(string $file) - { - $this->file = $file; - } + public function __construct(string $file) + { + $this->file = $file; + } } diff --git a/src/Pool.php b/src/Pool.php index b3e0ad6..6ea85a8 100644 --- a/src/Pool.php +++ b/src/Pool.php @@ -41,7 +41,7 @@ class Pool implements ArrayAccess protected $binary = PHP_BINARY; - protected $max_input_size = 100000; + protected $max_input_size = 100000; public function __construct() { @@ -150,7 +150,7 @@ public function add($process, ?int $outputLength = null): Runnable $process, $outputLength, $this->binary, - $this->max_input_size + $this->max_input_size ); } diff --git a/src/Runtime/ParentRuntime.php b/src/Runtime/ParentRuntime.php index 8616211..646f4ef 100644 --- a/src/Runtime/ParentRuntime.php +++ b/src/Runtime/ParentRuntime.php @@ -85,15 +85,15 @@ public static function encodeTask($task, ?int $max_input_size = 100000): string $task = new SerializableClosure($task); } - //serialize the task. If it's too big to pass on the command line, then we'll have to write it to a file and pass the filename instead... - $serialized_task = base64_encode(serialize($task)); - if (strlen($serialized_task) > $max_input_size) { - //write the serialized task to a temporary file... - $filename = tempnam(sys_get_temp_dir(), 'spatie_async_task_'); - file_put_contents($filename, $serialized_task); - $file_task = new FileTask($filename); - $serialized_task = base64_encode(serialize($file_task)); - } + //serialize the task. If it's too big to pass on the command line, then we'll have to write it to a file and pass the filename instead... + $serialized_task = base64_encode(serialize($task)); + if (strlen($serialized_task) > $max_input_size) { + //write the serialized task to a temporary file... + $filename = tempnam(sys_get_temp_dir(), 'spatie_async_task_'); + file_put_contents($filename, $serialized_task); + $file_task = new FileTask($filename); + $serialized_task = base64_encode(serialize($file_task)); + } return $serialized_task; } @@ -101,13 +101,13 @@ public static function encodeTask($task, ?int $max_input_size = 100000): string public static function decodeTask(string $task) { $decoded_task = unserialize(base64_decode($task)); - if (get_class($decoded_task) == 'Spatie\Async\FileTask') { - $filename = $decoded_task->file; - $decoded_task = unserialize(base64_decode(file_get_contents($filename))); - unlink($filename); - } + if (get_class($decoded_task) == 'Spatie\Async\FileTask') { + $filename = $decoded_task->file; + $decoded_task = unserialize(base64_decode(file_get_contents($filename))); + unlink($filename); + } - return $decoded_task; + return $decoded_task; } protected static function getId(): string