Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodmcnew/afe93fa819871011efd5aed28d8ab765 to your computer and use it in GitHub Desktop.
Save rodmcnew/afe93fa819871011efd5aed28d8ab765 to your computer and use it in GitHub Desktop.
<?php
class KeepAliveStream implements \Psr\Http\Message\StreamInterface
{
protected $doneMessage;
protected $keepAliveMessage;
protected $isDone = false;
public function __construct($keepAliveMessage = '.', $doneMessage = 'Done.')
{
$this->doneMessage = $doneMessage;
$this->keepAliveMessage = $keepAliveMessage;
}
public function __toString()
{
return '__toString() not supported by ' . __CLASS__;
}
public function close()
{
//nothing needed
}
public function detach()
{
return null;
}
public function getSize()
{
return null;
}
public function tell()
{
return null;
}
public function eof()
{
return $this->isDone;
}
public function isSeekable()
{
return false;
}
public function seek($offset, $whence = SEEK_SET)
{
// TODO: Implement seek() method.
}
public function rewind()
{
// TODO: Implement rewind() method.
}
public function isWritable()
{
return false;
}
public function write($string)
{
throw new \Exception('Writing not supported by ' . __CLASS__);
}
public function isReadable()
{
return true;
}
public function read($length)
{
throw new Exception('hello');
return $this->isDone ? $this->doneMessage : $this->keepAliveMessage;
}
public function getContents()
{
return '__getContents() not supported by ' . __CLASS__;
}
public function getMetadata($key = null)
{
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment