Skip to content

Instantly share code, notes, and snippets.

@nfreear
Created December 12, 2017 10:51
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nfreear/5fadc8c4e604486f0fec6c0f0f94be60 to your computer and use it in GitHub Desktop.
Save nfreear/5fadc8c4e604486f0fec6c0f0f94be60 to your computer and use it in GitHub Desktop.
fsockopen HTTP proxy test.
<?php
/**
* fsockopen HTTP proxy test.
*
* @author Nick Freear, 12-December-2017.
* @link https://gist.github.com/nfreear
* @link https://stackoverflow.com/questions/10886778/use-fsockopen-with-proxy
*/
define( 'PROXY_HOST', getenv( 'http_proxy' ) ? getenv( 'http_proxy' ) : 'wwwcache.open.ac.uk:80' );
define( 'PROXY_PORT', 80 );
define( 'TIMEOUT', 10 );
$url = 'https://www.google.com/';
$purl = parse_url( $url );
$host = $purl[ 'host' ];
$errno = $errstr = $reponse = null;
$fp = fsockopen( PROXY_HOST, PROXY_PORT, $errno, $errstr, TIMEOUT );
if ($fp) {
stream_set_timeout( $fp, TIMEOUT );
fputs( $fp, "GET $url HTTP/1.0\r\nHost: $host\r\n\r\n" );
while ( ! feof( $fp )) {
$reponse .= fgets( $fp, 64000 );
}
fclose( $fp );
}
print $reponse;
var_dump( PROXY_HOST, $url, $errno, $errstr );
// End.
@Sarfroz
Copy link

Sarfroz commented Dec 1, 2019

mate i have some questions can you help ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment