rialto-php / rialto

Manage Node resources with PHP
MIT License
170 stars 80 forks source link

Socket read exception handling - e.g. SOCKET_EAGAIN #37

Open mb0000 opened 3 years ago

mb0000 commented 3 years ago

I notice in nesk/rialto/src/ProcessSupervisor.php / readNextProcessValue that $this->client->selectRead($readTimeout) is called, but its boolean return value is not saved and, therefore, used. In at least one instance (say a SOCKET_EAGAIN exception), it would be helpful to use that value to possibly try again (as suggested in the PHP constants reference manual for SOCKET_EAGAIN) - this is a very crude retry mechanism, I admit:

$okayToRead = $this->client->selectRead( $readTimeout );
if (! $okayToRead) $okayToRead = $this->client->selectRead( $readTimeout );

In the event that a subsequent client->read takes place, it wiil except for other causes, but is less likely to for what would have been a SOCKET_EAGAIN error.

Perhaps worth investigating further for a better solution than the simple retry I suggest above?

The situation that caused this for me was a very large number of puPHPeteer page->evaluate() calls happening in a short space of time.