@@ -74,11 +74,13 @@ public function saveStateAsync(array $state): void
7474
7575 /**
7676 * Log STDERR messages from save process
77+ * @psalm-suppress PossiblyNullReference
7778 */
7879 $ this ->process ->stderr ->on ('data ' , function ($ data ) {
7980 $ this ->logger ->error ("save handler message: " . trim ($ data ));
8081 });
8182
83+ /** @psalm-suppress PossiblyInvalidArgument */
8284 $ process_decoded_stdout = new JsonRpcDecoder ($ this ->process ->stdout );
8385
8486 $ process_decoded_stdout ->on ('data ' , function ($ rpc ) {
@@ -89,10 +91,13 @@ public function saveStateAsync(array $state): void
8991 $ this ->saveStateSizeBytes = $ result ['saveStateSizeBytes ' ];
9092 $ this ->saveStateLastDuration = (int )round ((hrtime (true ) - $ result ['saveStateBeginTime ' ])/1e+6 ); //Milliseconds
9193 if ($ this ->saveStateLastDuration > 5000 ) {
92- $ this ->logger ->warning ('It took ' . $ this ->saveStateLastDuration . ' milliseconds to save state to disk ' );
94+ $ this ->logger ->warning ('It took ' . $ this ->saveStateLastDuration . ' milliseconds to save ' . round ( $ this -> saveStateSizeBytes / 1048576 , 2 ) . ' MB state to disk ' );
9395 }
9496 } else {
9597 $ error = $ rpc ->getError ();
98+ /**
99+ * @psalm-suppress PossiblyNullReference
100+ */
96101 $ this ->emit ('save:failed ' ,
97102 ['exception ' => new RuntimeException ($ error ->getMessage () . " : " . json_encode ($ error ->getData ()))]);
98103 }
@@ -105,12 +110,18 @@ public function saveStateAsync(array $state): void
105110
106111 $ uniqid = round (hrtime (true )/1e+3 ) . '. ' . bin2hex (random_bytes (4 ));
107112 $ rpc_request = new JsonRpcRequest (Scheduler::ACTION_RUN_METHOD , ['state ' => $ state , 'time ' => hrtime (true )], $ uniqid );
113+ /**
114+ * ReactPHP Process typehints aren't helpful here. stdin will be defined and be of type WritableStreamInterface
115+ * @psalm-suppress PossiblyUndefinedMethod
116+ * @psalm-suppress PossiblyNullReference
117+ */
108118 $ this ->process ->stdin ->write (json_encode ($ rpc_request ) . "\n" );
109119 }
110120
111121 public function saveStateSync (array $ state ): void
112122 {
113- $ filename = tempnam ("/tmp " , ".php-ce.state.tmp " );
123+ $ directory = dirname ($ this ->saveFileName );
124+ $ filename = tempnam ($ directory , ".php-ce.state.tmp " );
114125 if (false === $ filename ) {
115126 $ this ->emit ('save:failed ' , ['exception ' => new RuntimeException ("Error creating temporary save state file, check filesystem " )] );
116127 return ;
0 commit comments