บทนำ
การเข้าถึง filesystem และ stream wrappers ต่างๆ สามารถปรับแต่งได้ด้วย context options และ parameters ที่กำหนดค่าด้วยฟังก์ชัน stream_context_create() และ stream_context_set_option()
รายการต่อไปนี้แสดง socket context options ที่พร้อมใช้งานสำหรับ wrappers ทั้งหมดที่ทำงานผ่าน sockets เช่น tcp, http และ ftp
| bindto | ระบุ IP address (IPv4 หรือ IPv6) และ/หรือ port number ที่ใช้เข้าถึง network (ip:port สำหรับ IPv4 [ip]:port สำหรับ IPv6) |
| backlog | จำกัดจำนวน outstanding connections ใน listen queue ของ socket |
| ipv6_v6only | Override ค่า default ของ OS เกี่ยวกับการ map IPv4 เข้า IPv6 |
| so_reuseport | อนุญาต multiple bindings ไปยัง ip:port pair เดียวกัน |
| so_broadcast | เปิดใช้งานการส่งและรับข้อมูลไป/มาที่ broadcast addresses |
| tcp_nodelay | หาก TRUE ตั้งค่า SOL_TCP,NO_DELAY=1 อย่างเหมาะสม ปิด TCP Nagle algorithm |
ตัวอย่าง
<?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('https://www.example.com', false, $context); ?>