
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
PHP Socket context options
Introduction
Access to filesystem and various other stream wrappers can be customized by various context options and parameters configures by stream_context_create() and stream_context_set_option() functions.
Following list shows various socket context options are available for all wrappers that work over sockets, like tcp, http and ftp.
bindto | specifies the IP address (either IPv4 or IPv6) and/or the port number used to access the network. (ip:port for IPv4 [ip]:port for IPv6). |
backlog | limits number of outstanding connections in socket's listen queue. |
ipv6_v6only | Overrides the OS default regarding mapping IPv4 into IPv6. |
so_reuseport | Allows multiple bindings to a same ip:port pair. |
so_broadcast | Enables sending and receiving data to/from broadcast addresses. |
tcp_nodelay | If TRUE, sets SOL_TCP,NO_DELAY=1 appropriately, disabling TCP Nagle algorithm. |
Example
<?php // connect to the internet using the '192.168.0.100' IP $opts = array( 'socket' => array( 'bindto' => '192.168.0.100:0', ), ); // ...and use it to fetch the data echo file_get_contents('http://www.example.com', false, $context); ?>
- Related Articles
- PHP FTP context options
- PHP HTTP context options
- PHP MongoDB context options
- PHP Phar context options
- PHP SSL context options
- PHP Zip context options
- CURL context options in PHP
- PHP Context Parameters
- Socket programming In Python
- Socket Programming in C#
- Protect the Docker daemon socket
- What is Secure Socket Layer (SSL)?
- What are Ball and Socket joints?
- Socket Programming with Multi-threading in Python?
- Low-level networking interface in Python (socket)

Advertisements