Created
December 12, 2017 10:51
-
-
Save nfreear/5fadc8c4e604486f0fec6c0f0f94be60 to your computer and use it in GitHub Desktop.
fsockopen HTTP proxy test.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mate i have some questions can you help ??