MemoryRefresh!

Context



Questions Answers 0%

Pages   0 from 51
Questions   0 from 84

Reset



file_get_contents() - get the entire contents of the webpage as if it is a local file
<?php $contents = file_get_contents('http://studyon.minte9.com'); echo $contents; Stream context - allows you to add extra parameters to be used with streams
<?php $postVars = array( 'comment' => 'Test by stream', 'page_id' => '328', 'page_type' => '1', ); //echo file_get_contents("http://studyon.minte9.com/login"); die; $wrapperOptions = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query($postVars, '', '&'), 'timeout' => 5, ) ); $streamContext = stream_context_create($wrapperOptions); echo file_get_contents("http://www.fanlafel.ro/comment/frontend/add-comment", 0, $streamContext); // Insert comment You can create socket servers and clients using the stream functions.
<?php // -- server.php $socket = stream_socket_server("tcp://0.0.0.0:1037"); while ($conn = stream_socket_accept($socket)){ fwrite($conn, "Hello World"); fclose($conn); } fclose($socket);
<?php // -- client.php $socket = stream_socket_client("tcp://0.0.0.0:1037"); if ($socket) { while(!feof($socket)) { echo fread($socket, 100); } fclose($socket); }
Finally, we can run our server just like any other PHP script: $ php ./server.php And our client: $ php ./client.php Hello World
You can add a filter to the beginning and end to a stream.
<?php -- server.php $socket = stream_socket_server("tcp://0.0.0.0:1037"); while ($conn = stream_socket_accept($socket)){ // add filters stream_filter_append($conn, 'string.toupper'); stream_filter_append($conn, 'zlib.deflate'); fwrite($conn, "Hello World"); fclose($conn); } fclose($socket);
<?php -- client.php $socket = stream_socket_client("tcp://0.0.0.0:1037"); // add filter stream_filter_append($socket, 'zlib.inflate'); if ($socket) { while(!feof($socket)) { echo fread($socket, 100); } fclose($socket); } * Reference * stream_wrapper_register() User designed wrappers can be registered via stream_wrapper_register() * stream_filter_register() A filter is a final piece of code which may perform operations on data as it is being read from or written to a stream. Custom filters can be defined in a PHP script using stream_filter_register() * stream_context_create() A context is a set of parameters and wrapper specific options which modify or enhance the behavior of a stream. Contexts are created using stream_context_create() * stream_socket_client() Open Internet or Unix domain socket connection * stream_socket_server() Create an Internet or Unix domain server socket * stream_context_set_params() Set parameters for a stream/wrapper/context
Questions

Related pages

File open !
Read file !
Read csv !
File contents !
File cache and stats !
File lock !
File parse !
Context !
Network !


0% 100%
 
 
0 pages 51 pages
1) Stream context




2) To submit post vars to an url, use:




Last Review: n/a   Passed: n/a   Reviews: n/a   Next Review: n/a  


file_get_contents() - get the entire contents of the webpage as if it is a local file
<?php $contents = file_get_contents('http://studyon.minte9.com'); echo $contents; Stream context - allows you to add extra parameters to be used with streams
<?php $postVars = array( 'comment' => 'Test by stream', 'page_id' => '328', 'page_type' => '1', ); //echo file_get_contents("http://studyon.minte9.com/login"); die; $wrapperOptions = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query($postVars, '', '&'), 'timeout' => 5, ) ); $streamContext = stream_context_create($wrapperOptions); echo file_get_contents("http://www.fanlafel.ro/comment/frontend/add-comment", 0, $streamContext); // Insert comment You can create socket servers and clients using the stream functions.
<?php // -- server.php $socket = stream_socket_server("tcp://0.0.0.0:1037"); while ($conn = stream_socket_accept($socket)){ fwrite($conn, "Hello World"); fclose($conn); } fclose($socket);
<?php // -- client.php $socket = stream_socket_client("tcp://0.0.0.0:1037"); if ($socket) { while(!feof($socket)) { echo fread($socket, 100); } fclose($socket); }
Finally, we can run our server just like any other PHP script: $ php ./server.php And our client: $ php ./client.php Hello World
You can add a filter to the beginning and end to a stream.
<?php -- server.php $socket = stream_socket_server("tcp://0.0.0.0:1037"); while ($conn = stream_socket_accept($socket)){ // add filters stream_filter_append($conn, 'string.toupper'); stream_filter_append($conn, 'zlib.deflate'); fwrite($conn, "Hello World"); fclose($conn); } fclose($socket);
<?php -- client.php $socket = stream_socket_client("tcp://0.0.0.0:1037"); // add filter stream_filter_append($socket, 'zlib.inflate'); if ($socket) { while(!feof($socket)) { echo fread($socket, 100); } fclose($socket); } * Reference * stream_wrapper_register() User designed wrappers can be registered via stream_wrapper_register() * stream_filter_register() A filter is a final piece of code which may perform operations on data as it is being read from or written to a stream. Custom filters can be defined in a PHP script using stream_filter_register() * stream_context_create() A context is a set of parameters and wrapper specific options which modify or enhance the behavior of a stream. Contexts are created using stream_context_create() * stream_socket_client() Open Internet or Unix domain socket connection * stream_socket_server() Create an Internet or Unix domain server socket * stream_context_set_params() Set parameters for a stream/wrapper/context



More from Php

Basics
Variables
Operators
Function
Array
String
Streams
Uncategorized


More from Programming

Php
jQuery




Powered by minte9.com