本文整理汇总了PHP中fsockopen函数的典型用法代码示例。如果您正苦于以下问题:PHP fsockopen函数的具体用法?PHP fsockopen怎么用?PHP fsockopen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fsockopen函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: sendData
protected static function sendData($host, $POST, $HEAD, $filepath, $mediafile, $TAIL)
{
$sock = fsockopen("ssl://" . $host, 443);
fwrite($sock, $POST);
fwrite($sock, $HEAD);
//write file data
$buf = 1024;
$totalread = 0;
$fp = fopen($filepath, "r");
while ($totalread < $mediafile['filesize']) {
$buff = fread($fp, $buf);
fwrite($sock, $buff, $buf);
$totalread += $buf;
}
//echo $TAIL;
fwrite($sock, $TAIL);
sleep(1);
$data = fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
fclose($sock);
list($header, $body) = preg_split("/\\R\\R/", $data, 2);
$json = json_decode($body);
if (!is_null($json)) {
return $json;
}
return false;
}
开发者ID:abazad,项目名称:whatsappGUI,代码行数:32,代码来源:mediauploader.php
示例2: _recaptcha_http_post
/**
* Submits an HTTP POST to a reCAPTCHA server
* @param string $host
* @param string $path
* @param array $data
* @param int port
* @return array response
*/
function _recaptcha_http_post($host, $path, $data, $port = 80)
{
$req = _recaptcha_qsencode($data);
$proxy_host = "proxy.iiit.ac.in";
$proxy_port = "8080";
$http_request = "POST http://{$host}{$path} HTTP/1.0\r\n";
$http_request .= "Host: {$host}\r\n";
$http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
$http_request .= "Content-Length: " . strlen($req) . "\r\n";
$http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
$http_request .= "\r\n";
$http_request .= $req;
$response = '';
if (false == ($fs = @fsockopen($proxy_host, $proxy_port, $errno, $errstr, 10))) {
die('Could not open socket aah');
}
fwrite($fs, $http_request);
while (!feof($fs)) {
$response .= fgets($fs, 1160);
}
// One TCP-IP packet
fclose($fs);
$response = explode("\r\n\r\n", $response, 2);
return $response;
}
开发者ID:nehaljwani,项目名称:SSAD,代码行数:33,代码来源:recaptchaproxy.php
示例3: sockPost
/**
* http post request
*
* @codeCoverageIgnore
*
* @param $url
* @param array $query
* @param $port
*
* @return mixed
*/
public static function sockPost($url, $query, $port = 80)
{
$data = '';
$info = parse_url($url);
$fp = fsockopen($info['host'], $port, $errno, $errstr, 30);
if (!$fp) {
return $data;
}
$head = 'POST ' . $info['path'] . " HTTP/1.0\r\n";
$head .= 'Host: ' . $info['host'] . "\r\n";
$head .= 'Referer: http://' . $info['host'] . $info['path'] . "\r\n";
$head .= "Content-type: application/x-www-form-urlencoded\r\n";
$head .= 'Content-Length: ' . strlen(trim($query)) . "\r\n";
$head .= "\r\n";
$head .= trim($query);
$write = fwrite($fp, $head);
$header = '';
while ($str = trim(fgets($fp, 4096))) {
$header .= $str;
}
while (!feof($fp)) {
$data .= fgets($fp, 4096);
}
return $data;
}
开发者ID:jgglg,项目名称:phpsms,代码行数:36,代码来源:Agent.php
示例4: sendMemcacheCommand
function sendMemcacheCommand($server, $port, $command)
{
$s = @fsockopen($server, $port);
if (!$s) {
die("Cant connect to:" . $server . ':' . $port);
}
fwrite($s, $command . "\r\n");
$buf = '';
while (!feof($s)) {
$buf .= fgets($s, 256);
if (strpos($buf, "END\r\n") !== false) {
// stat says end
break;
}
if (strpos($buf, "DELETED\r\n") !== false || strpos($buf, "NOT_FOUND\r\n") !== false) {
// delete says these
break;
}
if (strpos($buf, "OK\r\n") !== false) {
// flush_all says ok
break;
}
}
fclose($s);
return parseMemcacheResults($buf);
}
开发者ID:hartum,项目名称:basezf,代码行数:26,代码来源:memcache.php
示例5: downloadToString
function downloadToString()
{
$crlf = "\r\n";
// generate request
$req = 'GET ' . $this->_uri . ' HTTP/1.0' . $crlf . 'Host: ' . $this->_host . $crlf . $crlf;
// fetch
$this->_fp = fsockopen(($this->_protocol == 'https' ? 'ssl://' : '') . $this->_host, $this->_port);
fwrite($this->_fp, $req);
while (is_resource($this->_fp) && $this->_fp && !feof($this->_fp)) {
$response .= fread($this->_fp, 1024);
}
fclose($this->_fp);
// split header and body
$pos = strpos($response, $crlf . $crlf);
if ($pos === false) {
return $response;
}
$header = substr($response, 0, $pos);
$body = substr($response, $pos + 2 * strlen($crlf));
// parse headers
$headers = array();
$lines = explode($crlf, $header);
foreach ($lines as $line) {
if (($pos = strpos($line, ':')) !== false) {
$headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos + 1));
}
}
// redirection?
if (isset($headers['location'])) {
$http = new ilHttpRequest($headers['location']);
return $http->DownloadToString($http);
} else {
return $body;
}
}
开发者ID:khanhnnvn,项目名称:ilias_E-learning,代码行数:35,代码来源:class.ilHttpRequest.php
示例6: http_send
function http_send($_url, $_body)
{
$errno = 0;
$errstr = '';
$timeout = 10;
$fp = fsockopen(_IP_, _PORT_, $errno, $errstr, $timeout);
if (!$fp) {
return FALSE;
}
$_head = "POST /" . $_url . " HTTP/1.1\r\n";
$_head .= "Host: " . _IP_ . ":" . _PORT_ . "\r\n";
$_head .= "Content-Type: Text/plain\r\n";
if (!$_body) {
$body_len = 0;
} else {
$body_len = strlen($_body);
}
$send_pkg = $_head . "Content-Length:" . $body_len . "\r\n\r\n" . $_body;
ilog(iLOG_INFO, " -----> http_send url: " . $_url);
ilog(iLOG_INFO, " -----> http_send body: " . $_body);
if (fputs($fp, $send_pkg) === FALSE) {
return FALSE;
}
//设置3s超时
stream_set_timeout($fp, 3);
while (!feof($fp)) {
ilog(iLOG_INFO, " -----> rsp: " . fgets($fp, 128));
}
if ($fp) {
fclose($fp);
}
return TRUE;
}
开发者ID:yonglinchen,项目名称:shopping,代码行数:33,代码来源:ihttp.php
示例7: send_request_via_fsockopen1
function send_request_via_fsockopen1($host, $path, $content)
{
$posturl = "ssl://" . $host;
$header = "Host: {$host}\r\n";
$header .= "User-Agent: PHP Script\r\n";
$header .= "Content-Type: text/xml\r\n";
$header .= "Content-Length: " . strlen($content) . "\r\n";
$header .= "Connection: close\r\n\r\n";
$fp = fsockopen($posturl, 443, $errno, $errstr, 30);
if (!$fp) {
$response = false;
} else {
error_reporting(E_ERROR);
fputs($fp, "POST {$path} HTTP/1.1\r\n");
fputs($fp, $header . $content);
fwrite($fp, $out);
$response = "";
while (!feof($fp)) {
$response = $response . fgets($fp, 128);
}
fclose($fp);
error_reporting(E_ALL ^ E_NOTICE);
}
return $response;
}
开发者ID:shaheerali49,项目名称:herozfitcart,代码行数:25,代码来源:authnetfunction.php
示例8: __construct
/**
* Construct a new NetworkPrintConnector
*
* @param string $ip IP address or hostname to use.
* @param string $port The port number to connect on.
* @throws Exception Where the socket cannot be opened.
*/
public function __construct($ip, $port = "9100")
{
$this->fp = @fsockopen($ip, $port, $errno, $errstr);
if ($this->fp === false) {
throw new Exception("Cannot initialise NetworkPrintConnector: " . $errstr);
}
}
开发者ID:mike42,项目名称:escpos-php,代码行数:14,代码来源:NetworkPrintConnector.php
示例9: n2k_request_response
function n2k_request_response($request, $description = 'N2K')
{
$errno = 0;
$errstr = '';
$n2k = @fsockopen('localhost', 2597, $errno, $errstr, 15);
if (!$n2k) {
echo "Cannot connect to N2KD: {$errstr}\n";
exit(1);
}
#
# Ask for device list
#
if ($request !== null) {
fwrite($n2k, $request . "\n");
}
$s = '';
while (!feof($n2k)) {
$s .= fgets($n2k, 1024);
}
fclose($n2k);
$data = json_decode($s, true);
if (!is_array($data)) {
echo "Error: received invalid response for {$description} request\n";
exit(1);
}
return $data;
}
开发者ID:nauta42,项目名称:canboat,代码行数:27,代码来源:airmar.php
示例10: openstats
function openstats()
{
$fp = fsockopen($this->host, $this->port, $errno, $errstr, 10);
if (!$fp) {
$this->_error = "{$errstr} ({$errno})";
return 0;
} else {
fputs($fp, "GET /admin.cgi?pass=" . $this->passwd . "&mode=viewxml HTTP/1.0\r\n");
fputs($fp, "User-Agent: Mozilla\r\n\r\n");
while (!feof($fp)) {
$this->_xml .= fgets($fp, 512);
}
fclose($fp);
if (stristr($this->_xml, "HTTP/1.0 200 OK") == true) {
// <-H> Thanks to Blaster for this fix.. trim();
$this->_xml = trim(substr($this->_xml, 42));
} else {
$this->_error = "Bad login";
return 0;
}
$xmlparser = xml_parser_create();
if (!xml_parse_into_struct($xmlparser, $this->_xml, $this->_values, $this->_indexes)) {
$this->_error = "Unparsable XML";
return 0;
}
xml_parser_free($xmlparser);
return 1;
}
}
开发者ID:Karpec,项目名称:gizd,代码行数:29,代码来源:shoutcast.class.php
示例11: __construct
/**
* Constructor.
*
* @access public
* @param string $host Redis host
* @param string $port Redis port
*/
public function __construct($host, $port = 6379)
{
$this->connection = @fsockopen('tcp://' . $host, $port, $errNo, $errStr);
if (!$this->connection) {
throw new RedisException(vsprintf("%s(): %s", [__METHOD__, $errStr]), (int) $errNo);
}
}
开发者ID:muhammetardayildiz,项目名称:framework,代码行数:14,代码来源:Connection.php
示例12: DoTest
function DoTest($testname, $param, $hostname, $timeout, $params)
{
echo "Called for " . $hostname . " port " . $param . " timeout " . $timeout . "\n";
$timer = new TFNTimer();
$ip = ip_lookup($hostname);
echo $hostname . " => " . $ip . "\n";
if ($ip == "0") {
return -2;
}
// lookup failed
echo "Lookup Successful\n";
$errno = 0;
$errstr = "";
$timer->Start();
echo "Doing fsockopen()\n";
$fp = @fsockopen($ip, $param, $errno, $errstr, $timeout);
$elapsed = $timer->Stop();
echo "FP is : ";
echo $fp;
echo "\n";
if ($fp === false) {
return -1;
}
// open failed
echo "Closing\n";
@fclose($fp);
return $elapsed;
}
开发者ID:purplepixie,项目名称:freenats,代码行数:28,代码来源:tcpdebug.php
示例13: get
function get()
{
if (!empty($this->url)) {
$fp = fsockopen($this->host, 80, $errno, $errstr, 30);
if (!$fp) {
$this->status = false;
//$this->error['error_number'] = $errno;
//$this->error['error_msg'] = $errstr;
} else {
// here, we use double quotes to replace single quotes, or 400 error.
fputs($fp, 'GET ' . $this->path . " HTTP/1.1\r\n");
fputs($fp, 'User-Agent: ' . $this->user_agent . "\r\n");
fputs($fp, 'Host: ' . $this->host . "\r\n");
fputs($fp, "Connection: close\r\n\r\n");
while (!feof($fp)) {
$line = fgets($fp);
$this->content .= $line;
}
fclose($fp);
if (preg_match('/sogourank=(\\d+)/', $this->content, $matches) > 0) {
$this->response .= $matches[1];
}
}
} else {
$this->status = false;
}
}
开发者ID:jameyu,项目名称:Test,代码行数:27,代码来源:SougouRank.php
示例14: request
public function request()
{
if ($this->_uri === null) {
throw new Modela_Exception("uri is not valid");
}
$sock = @fsockopen($this->_uriParts["host"], $this->_uriParts["port"]);
if (!$sock) {
throw new Modela_Exception('unable to open socket');
}
$requestString = $this->_method . " " . $this->_uriParts["path"];
if ($this->_uriParts["query"]) {
$requestString .= "?" . $this->_uriParts["query"];
}
$socketData = $requestString . self::HTTP_CRLF;
if ($this->_data) {
$socketData .= "Content-length: " . strlen($this->_data) . self::HTTP_CRLF;
$socketData .= "Content-type: application/json" . self::HTTP_CRLF;
$socketData .= "Connection: close" . self::HTTP_CRLF;
$socketData .= self::HTTP_CRLF;
$socketData .= $this->_data . self::HTTP_CRLF;
}
$socketData .= self::HTTP_CRLF . self::HTTP_CRLF;
fwrite($sock, $socketData);
$output = '';
$output .= stream_get_contents($sock);
list($this->_headers, $this->_response) = explode("\r\n\r\n", $output);
$this->_response = trim($this->_response);
fclose($sock);
return $this->_response;
}
开发者ID:jimbojsb,项目名称:modela,代码行数:30,代码来源:Http.php
示例15: postSMS
private static function postSMS($http, $data)
{
$post = '';
$row = parse_url($http);
$host = $row['host'];
$port = !empty($row['port']) ? $row['port'] : 80;
$file = $row['path'];
while (list($k, $v) = each($data)) {
$post .= rawurlencode($k) . "=" . rawurlencode($v) . "&";
}
$post = substr($post, 0, -1);
$len = strlen($post);
$fp = @fsockopen($host, $port, $errno, $errstr, 10);
// var_dump($fp);exit;
if (!$fp) {
return "{$errstr} ({$errno})\n";
} else {
$receive = '';
$out = "POST {$file} HTTP/1.0\r\n";
$out .= "Host: {$host}\r\n";
$out .= "Content-type: application/x-www-form-urlencoded\r\n";
$out .= "Connection: Close\r\n";
$out .= "Content-Length: {$len}\r\n\r\n";
$out .= $post;
fwrite($fp, $out);
while (!feof($fp)) {
$receive .= fgets($fp, 128);
}
fclose($fp);
$receive = explode("\r\n\r\n", $receive);
unset($receive[0]);
// var_dump($receive);exit;
return implode("", $receive);
}
}
开发者ID:TipTimesPHP,项目名称:tyj_oa,代码行数:35,代码来源:sendSMS.class.php
示例16: sendit
function sendit($param)
{
$prefix = $_POST['prefix'];
$data = $_POST['sql_text'];
$host = $_POST['hostname'];
$page = isset($_POST['dir']) ? '/' . $_POST['dir'] : '';
$page .= '/modules.php?name=Search';
$method = $_POST['method'];
$ref_text = $_POST['ref_text'];
$user_agent = $_POST['user_agent'];
$result = '';
$sock = fsockopen($host, 80, $errno, $errstr, 50);
if (!$sock) {
die("{$errstr} ({$errno})\n");
}
fputs($sock, "{$method} /{$page} HTTP/1.0\r\n");
fputs($sock, "Host: {$host}" . "\r\n");
fputs($sock, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($sock, "Content-length: " . strlen($data) . "\r\n");
fputs($sock, "Referer: {$ref_text}" . "\r\n");
fputs($sock, "User-Agent: {$user_agent}" . "\r\n");
fputs($sock, "Accept: */*\r\n");
fputs($sock, "\r\n");
fputs($sock, "{$data}\r\n");
fputs($sock, "\r\n");
while (!feof($sock)) {
$result .= fgets($sock, 8192);
}
fclose($sock);
return $result;
}
开发者ID:SuperQcheng,项目名称:exploit-database,代码行数:31,代码来源:4965.php
示例17: getpr
function getpr($url)
{
$ch = getch($url);
$fp = fsockopen(self::GOOGLEHOST, 80, $errno, $errstr, 30);
if ($fp) {
$out = "GET /search?client=navclient-auto&ch={$ch}&features=Rank&q=info:{$url} HTTP/1.1\r\n";
//echo "<pre>$out</pre>\n"; //debug only
$out .= "User-Agent: " . self::GOOGLEUA . "\r\n";
$out .= "Host: " . self::GOOGLEHOST . "\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
//$pagerank = substr(fgets($fp, 128), 4); //debug only
//echo $pagerank; //debug only
while (!feof($fp)) {
$data = fgets($fp, 128);
//echo $data;
$pos = strpos($data, "Rank_");
if ($pos === false) {
} else {
$pr = substr($data, $pos + 9);
$pr = trim($pr);
$pr = str_replace("\n", '', $pr);
return $pr;
}
}
//else { echo "$errstr ($errno)<br />\n"; } //debug only
fclose($fp);
}
}
开发者ID:laiello,项目名称:lion-framework,代码行数:29,代码来源:GooglePageRankChecker.class.php
示例18: send_mail
public function send_mail()
{
$talk = array();
if ($SMTPIN = fsockopen($this->SmtpServer, $this->PortSMTP)) {
fputs($SMTPIN, "EHLO " . $HTTP_HOST . "\r\n");
$talk["hello"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, "auth login\r\n");
$talk["res"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, $this->SmtpUser . "\r\n");
$talk["user"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, $this->SmtpPass . "\r\n");
$talk["pass"] = fgets($SMTPIN, 256);
fputs($SMTPIN, "MAIL FROM: <" . $this->from . ">\r\n");
$talk["From"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, "RCPT TO: <" . $this->to . ">\r\n");
$talk["To"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, "DATA\r\n");
$talk["data"] = fgets($SMTPIN, 1024);
//Construct Headers
$headers = "MIME-Version: 1.0" . $this->newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $this->newLine;
$headers .= "From: <" . $this->from . ">" . $this->newLine;
$headers .= "To: <" . $this->to . ">" . $this->newLine;
$headers .= "Bcc: {$this->newLine}";
$headers .= "Subject: " . $this->subject . $this->newLine;
fputs($SMTPIN, $headers . "\r\n\r\n" . $this->body . "\r\n.\r\n");
$talk["send"] = fgets($SMTPIN, 256);
//CLOSE CONNECTION AND EXIT ...
fputs($SMTPIN, "QUIT\r\n");
fclose($SMTPIN);
}
return $talk;
}
开发者ID:passionybr2003,项目名称:ifsnew,代码行数:33,代码来源:SmtpMail.php
示例19: verify_notify
/**
* 返回通知结果
*
* @author Garbin
* @param array $order_info
* @param bool $strict
* @return array
*/
function verify_notify($order_info, $strict = false)
{
if (empty($order_info)) {
$this->_error('order_info_empty');
return false;
}
$merchant_id = $this->_config['paypal_account'];
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&{$key}={$value}";
}
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$order_sn = $_POST['invoice'];
$memo = empty($_POST['memo']) ? '' : $_POST['memo'];
if (!$fp) {
fclose($fp);
return false;
} else {
fputs($fp, $header . $req);
while (!feof($fp)) {
$res = fgets($fp, 1024);
if (strcmp($res, 'VERIFIED') == 0) {
if ($payment_status != 'Completed' && $payment_status != 'Pending') {
fclose($fp);
return false;
}
if ($receiver_email != $merchant_id) {
fclose($fp);
return false;
}
if ($order_info['order_amount'] != $payment_amount) {
fclose($fp);
$this->_error('money_inequalit');
return false;
}
if ($this->_config['paypal_currency'] != $payment_currency) {
fclose($fp);
return false;
}
fclose($fp);
return array('target' => ORDER_ACCEPTED);
} elseif (strcmp($res, 'INVALID') == 0) {
fclose($fp);
return false;
}
}
}
}
开发者ID:BGCX261,项目名称:zhou3liu-svn-to-git,代码行数:68,代码来源:paypal.payment.php
示例20: SendMail
function SendMail()
{
if ($SMTPIN = fsockopen($this->SmtpServer, $this->PortSMTP)) {
fputs($SMTPIN, "EHLO " . $HTTP_HOST . "\r\n");
$talk["hello"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, "auth login\r\n");
$talk["res"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, $this->SmtpUser . "\r\n");
$talk["user"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, $this->SmtpPass . "\r\n");
$talk["pass"] = fgets($SMTPIN, 256);
fputs($SMTPIN, "MAIL FROM: <" . $this->from . ">\r\n");
$talk["From"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, "RCPT TO: <" . $this->to . ">\r\n");
$talk["To"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, "DATA\r\n");
$talk["data"] = fgets($SMTPIN, 1024);
fputs($SMTPIN, "To: <" . $this->to . ">\r\nFrom: <" . $this->from . ">\r\nSubject:" . $this->subject . "\r\n\r\n\r\n" . $this->body . "\r\n.\r\n");
$talk["send"] = fgets($SMTPIN, 256);
//CLOSE CONNECTION AND EXIT ...
fputs($SMTPIN, "QUIT\r\n");
fclose($SMTPIN);
//
}
return $talk;
}
开发者ID:xhsui,项目名称:ci_system,代码行数:26,代码来源:SMTPClass.php
注:本文中的fsockopen函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论