FsockopenSocket.php 620 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace Pheanstalk\Socket;
  3. use Pheanstalk\Exception\ConnectionException;
  4. /**
  5. * A Socket implementation using the fsockopen
  6. */
  7. class FsockopenSocket extends FileSocket
  8. {
  9. public function __construct(
  10. string $host,
  11. int $port,
  12. int $connectTimeout
  13. ) {
  14. if (!function_exists('fsockopen')) {
  15. throw new \Exception('Fsockopen not found');
  16. }
  17. $this->socket = @fsockopen($host, $port, $error, $errorMessage, $connectTimeout);
  18. if ($this->socket === false) {
  19. throw new ConnectionException($error, $errorMessage);
  20. }
  21. }
  22. }