- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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); ?>
Advertisements