open() public method

Opens the socket and sets its timeout value.
public open ( array $options = [] ) : mixed
$options array Update the config settings.
return mixed Returns `false` if the socket configuration does not contain the `'scheme'` or `'host'` settings, or if configuration fails, otherwise returns a resource stream.
コード例 #1
0
ファイル: ContextTest.php プロジェクト: EHER/chegamos
 public function testWriteAndRead()
 {
     $stream = new Context($this->_testConfig);
     $this->assertTrue(is_resource($stream->open()));
     $this->assertTrue(is_resource($stream->resource()));
     $response = $stream->send(new Request(), array('response' => 'lithium\\net\\http\\Response'));
     $this->assertTrue($response instanceof Response);
     $this->assertEqual(trim(file_get_contents($this->_testUrl)), trim($response->body()));
     $this->assertTrue($stream->eof());
 }
コード例 #2
0
 public function testContextAdapter()
 {
     $socket = new Context($this->_testConfig);
     $this->assertTrue($socket->open());
     $response = $socket->send();
     $this->assertTrue($response instanceof Response);
     $expected = 'google.com';
     $result = $response->host;
     $this->assertEqual($expected, $result);
     $result = $response->body();
     $this->assertPattern("/<title[^>]*>.*Google.*<\\/title>/im", (string) $result);
 }
コード例 #3
0
ファイル: SocketTest.php プロジェクト: Nys/lithium
 public function testContextAdapter()
 {
     $socket = new Context($this->_testConfig);
     $this->assertTrue($socket->open());
     $response = $socket->send();
     $this->assertTrue($response instanceof \lithium\net\http\Response);
     $expected = 'www.lithify.me';
     $result = $response->host;
     $this->assertEqual($expected, $result);
     $result = $response->body();
     $this->assertPattern("/<title[^>]*>.*Lithium.*<\\/title>/im", (string) $result);
 }
コード例 #4
0
 public function testSendWithObject()
 {
     $stream = new Context($this->_testConfig);
     $this->assertTrue(is_resource($stream->open()));
     $result = $stream->send(new Request($this->_testConfig), array('response' => 'lithium\\net\\http\\Response'));
     $this->assertTrue($result instanceof Response);
     $this->assertPattern("/^HTTP/", (string) $result);
     $this->assertTrue($stream->eof());
 }
コード例 #5
0
ファイル: ContextTest.php プロジェクト: nilamdoc/KYCGlobal
 public function testContextAdapter()
 {
     $socket = new Context($this->_testConfig);
     $this->assertNotEmpty($socket->open());
     $response = $socket->send();
     $this->assertInstanceOf('lithium\\net\\http\\Response', $response);
     $expected = 'google.com';
     $result = $response->host;
     $this->assertEqual($expected, $result);
     $result = $response->body();
     $this->assertPattern("/<title[^>]*>301 Moved<\\/title>/im", (string) $result);
 }