Separates any underlying resources from the stream.

After the stream has been detached, the stream is in an unusable state.

@return resource|null Underlying PHP stream, if any
509582
public function detach()
    {
        $resource = $this->resource;

        $this->resource = null;
        $this->stream = null;
        $this->pointer = 0;
        $this->seekable = true;
        $this->writable = true;

        return $resource;
    }
366661
public function openStream()
    {
        $url      = $this->endpoints[$this->method];
        $urlParts = parse_url($url);
        $isSecure = ($urlParts['scheme'] == 'https');
        $scheme   = $isSecure ? 'ssl://' : 'tcp://';
        $port     = $isSecure ? 443 : 80;

        $requestParams = [];

        if ($this->lang) {
            $requestParams['language'] = $this->lang;
        }

        if (($this->method === self::METHOD_FILTER || $this->method === self::METHOD_USER) && count($this->trackWords) > 0) {
            $requestParams['track'] = implode(',', $this->trackWords);
        }
        if (($this->method === self::METHOD_FILTER || $this->method === self::METHOD_SITE) && count($this->followIds) > 0) {
            $requestParams['follow'] = implode(',', $this->followIds);
        }

        if ($this->method === self::METHOD_FILTER && $this->location) {
            $requestParams['locations'] = implode(',', $this->location->getBoundingBox());
        }

        if ($this->count <> 0) {
            $requestParams['count'] = $this->count;
        }

        $this->stop();

        return $this->connectAsync($isSecure, $urlParts['host'], $port)
        ->then(function() use ($url, $requestParams) {
            $this->connectRetryCount = 0;
            return $this->readFromStream
              ($url, $requestParams, $this->oauth->getAuthorizationHeader('POST', $url, $requestParams))
            ->then(function($res) {
                if ($this->isStopping) {
                  return;
                }
                if ($this->readRetryCount == 0)
                  $this->emit("online", [0]);
                $this->readRetryCount++;
                $err = null;
                if ($res['type'] == 'http')
                    $err = $this->getExceptionForHttpStatus($res['code']);
                else if ($res['type'] == 'stalled')
                    $err = new \TwitterException("Stalled");
                else if ($res['type'] == 'disconnected')
                    $err = new \TwitterException("Disconnected");
                else if ($res['type'] == 'err')
                    $err = $res['err'];
                if ($this->readRetryCount >= self::MAX_RETRY_ATTEMPTS) {
                    throw $err;
                } else {
                    $this->emit("warning", [$err]);
                    if ($res['type'] == 'http') {
                        $is420 = (isset($res['code']) && $res['code'] == 420);
                        $time = $is420 ? self::RETRY_TIME_420 : self::RETRY_TIME;
                        $time = $time * pow(2, $this->readRetryCount - 1);
                        $max = ($is420 ? self::MAX_RETRY_TIME_420 : self::MAX_RETRY_TIME);
                        $time = min($time, $max);
                    } else {
                        $time = 0.5;
                    }
                    echo "Stream Retry #{$this->readRetryCount} in $time s - " . print_r($res, true) . "\n";
                    $this->loop->addTimer($time, function() {
                        $this->openStream();
                    });
                }
            })
            ->otherwise(function($err) {
                throw $err;
            });
        })
        ->otherwise(function($err) {
            $this->connectRetryCount = 0;
            $this->readRetryCount = 0;
            $this->emit("error", [$err]);
            $this->emit("online", [0]);
        });
    }
594379
public function getContents()
    {
        if (!$this->isReadable()) {
            return '';
        }
        rewind($this->resource);

        $result = stream_get_contents($this->resource);
        if (!$result) {
            return '';
        }
        return $result;
    }
603629
public function nextTerm()
    {
        while (($termStream = $this->_termsStreamQueue->pop()) !== null) {
            if ($this->_termsStreamQueue->top() === null 
                || $this->_termsStreamQueue->top()->currentTerm()->key() !=                $termStream->currentTerm()->key()
            ) {
                // We got new term
                $this->_lastTerm = $termStream->currentTerm();

                if ($termStream->nextTerm() !== null) {
                    // Put segment back into the priority queue
                    $this->_termsStreamQueue->put($termStream);
                }

                return $this->_lastTerm;
            }

            if ($termStream->nextTerm() !== null) {
                // Put segment back into the priority queue
                $this->_termsStreamQueue->put($termStream);
            }
        }

        // End of stream
        $this->_lastTerm = null;

        return null;
    }
278530
public function getResource()
    {
        if ($this->getEvent() && $this->event->getTarget() instanceof ResourceInterface) {
            return $this->event->getTarget();
        }

        return null;
    }
1370921
public function detach() {
        if($this->__parent) {
            $this->__parent->offsetUnset($this->__name);
        }

        $this->__parent = NULL;
        $this->__name = NULL;
        return $this;
    }
64329
public function close()
    {
        if ($this->resource) {
            // Error suppression, as resource might already be closed
            $meta = @\stream_get_meta_data($this->resource);

            if ($meta && \strpos($meta["mode"], "+") !== false) {
                @\stream_socket_shutdown($this->resource, \STREAM_SHUT_WR);
            } else {
                @\fclose($this->resource);
            }
        }

        $this->free();
    }
614765
public static function make()
    {
        $stream = new Stream();
        $source = static::getSource();
        $stream->copy($source);

        if (! static::$source) {
            fclose($source);
        }

        return $stream;
    }
1078539
public function createInputStream(): InputStream {
		$this->ensureValid();
		try {
			return IoUtils::createSafeFileInputStream($this->fsPath);
		} catch (CouldNotAchieveFlockException $e) {
			return new FileResourceStream($this->fsPath, 'r');
		}
	}
652099
public function read()
    {
        if (!$this->valid()) {
            return null;
        }

        // keep a local copy of the resource; the next() call could change the cached one
        $resource = $this->resource;

        $item = $this->current();
        $this->next();

        // serialize the item
        $event = new ResourceSerializeEvent($resource, $item);
        $this->eventDispatcher->dispatch(FeedEvents::RESOURCE_PRE_SERIALIZE, $event);
        $item = $this->serialize($item);
        $this->eventDispatcher->dispatch(FeedEvents::RESOURCE_POST_SERIALIZE, $event);

        return $item;
    }
481504
public function read() {
		if (!is_resource($this->_resource)) {
			return false;
		}
		$meta = stream_get_meta_data($this->_resource);
		if (isset($meta['wrapper_data'])) {
			$headers = join("\r\n", $meta['wrapper_data']) . "\r\n\r\n";
		} else {
			$headers = null;
		}
		return $headers . stream_get_contents($this->_resource);
	}
856084
public function tell()
    {
        if (is_resource($this->stream) !== false) {
            $position = ftell($this->stream);
            if ($position !== false) {
                return $position;
            }
        }
        throw new RuntimeException('Could not get the position of the pointer in stream');
    }
623153
public function getContents()
    {
        $this->ensureResourceReadable();

        $result = stream_get_contents($this->resource);
        if ($result === false) {
            throw new \RuntimeException('Error reading from stream', 1453892266);
        }

        return $result;
    }
149638
public function closeTermsStream()
    {
        while (($termStream = $this->_termsStreamQueue->pop()) !== null) {
            $termStream->closeTermsStream();
        }

        $this->_termsStreamQueue = null;
        $this->_lastTerm         = null;
    }
1329347
public function serialize()
    {
        $debugOutputResource = null;
        if (is_resource($this->debugOutputResource)) {
            $metadata = stream_get_meta_data($this->debugOutputResource);
            $debugOutputResource = [
                'uri' => $metadata['uri'],
                'mode' => $metadata['mode']
            ];
        }

        return serialize([
            $this->messageKey,
            $this->batchEnabled,
            $this->metadataProvider,
            $this->debugOutput,
            $this->clientConfig,
            $this->batchMethod,
            $this->logName,
            $debugOutputResource
        ]);
    }
880240
public function detach()
    {
        $stream = $this->stream;

        $this->stream = null;
        $this->readable = null;
        $this->writable = null;
        $this->seekable = null;
        $this->size = null;

        return $stream;
    }
772741
public function load()
    {
        $debuggeeId = null;
        $breakpoints = [];

        // Acquire a read lock (non-blocking). If we fail (file is locked
        // for writing), then we return an empty list of breakpoints and
        // skip debugging for this request.
        try {
            $contents = $this->getLock()->synchronize(function () {
                return file_get_contents($this->filename);
            }, [
                'blocking' => false
            ]);
            $data = unserialize($contents);
            $debuggeeId = $data['debuggeeId'];
            $breakpoints = $data['breakpoints'];
        } catch (\RuntimeException $e) {
            // Do nothing
        }
        return [$debuggeeId, $breakpoints];
    }