简体   繁体   English

如何使用 PHP 或 JavaScript 获取客户端响应标头?

[英]How to get client response headers with PHP or JavaScript?

guys.伙计们。 I'm building a crypto coin mining pool, the original pool was based off of Node.JS.我正在构建一个加密货币矿池,原始矿池基于 Node.JS。 Which Node.JS is not up to the fast pace of the mining pool.哪个Node.JS跟不上矿池的快节奏。 So I was building the pool to run in NGINX and PHP.所以我正在构建池以在 NGINX 和 PHP 中运行。 How the miner works, it interacts with the pool API.矿工如何工作,它与矿池 API 交互。 The miner has some important information in headers, such as miner type, version, capacity, and etc. Is there a way to get the headers with PHP preferably, if not can it be done with JavaScript.矿工在headers里面有一些重要的信息,比如矿机类型,版本,容量等。有没有办法最好用PHP来获取headers,如果没有可以用JavaScript来完成。 Thanks.谢谢。 :) :)

With Node.JS I was using: req.headers我使用的是req.headersreq.headers

This is what I have tried in PHP:这是我在 PHP 中尝试过的:

$_SERVER["USER"] = www-data
$_SERVER["HOME"] = /var/www
$_SERVER["HTTP_HOST"] = 10.10.31.95
$_SERVER["HTTP_USER_AGENT"] = Jetty/9.4.2.v20170220
$_SERVER["HTTP_ACCEPT_ENCODING"] = gzip
$_SERVER["REDIRECT_STATUS"] = 200
$_SERVER["SERVER_NAME"] = _
$_SERVER["SERVER_PORT"] = 80
$_SERVER["SERVER_ADDR"] = 10.10.31.95
$_SERVER["REMOTE_PORT"] = 57488
$_SERVER["REMOTE_ADDR"] = 10.10.30.0
$_SERVER["SERVER_SOFTWARE"] = nginx/1.10.3
$_SERVER["GATEWAY_INTERFACE"] = CGI/1.1
$_SERVER["REQUEST_SCHEME"] = http
$_SERVER["SERVER_PROTOCOL"] = HTTP/1.1
$_SERVER["DOCUMENT_ROOT"] = /var/www/html
$_SERVER["DOCUMENT_URI"] = /burst.php
$_SERVER["REQUEST_URI"] = /burst?requestType=getMiningInfo
$_SERVER["SCRIPT_NAME"] = /burst.php
$_SERVER["CONTENT_LENGTH"] = 
$_SERVER["CONTENT_TYPE"] = 
$_SERVER["REQUEST_METHOD"] = GET
$_SERVER["QUERY_STRING"] = requestType=getMiningInfo
$_SERVER["SCRIPT_FILENAME"] = /var/www/html/burst.php
$_SERVER["PATH_INFO"] = 
$_SERVER["FCGI_ROLE"] = RESPONDER
$_SERVER["PHP_SELF"] = 
$_SERVER["REQUEST_TIME_FLOAT"] = 1507362021.8898
$_SERVER["REQUEST_TIME"] = 1507362021

This works这有效

function get_contents() {
  file_get_contents("http://example.com");
  var_dump($http_response_header);
}
get_contents();
var_dump($http_response_header);

Out put.输出。

array(13) {
[0]=> string(15) "HTTP/1.0 200 OK" 
[1]=> string(20) "Accept-Ranges: bytes" 
[2]=> string(29) "Cache-Control: max-age=604800" 
[3]=> string(23) "Content-Type: text/html" 
[4]=> string(35) "Date: Sat, 07 Oct 2017 23:51:45 GMT" 
[5]=> string(22) "Etag: "359670651+gzip"" 
[6]=> string(38) "Expires: Sat, 14 Oct 2017 23:51:45 GMT" 
[7]=> string(44) "Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT" 
[8]=> string(22) "Server: ECS (lga/1386)" 
[9]=> string(21) "Vary: Accept-Encoding" 
[10]=> string(12) "X-Cache: HIT" 
[11]=> string(20) "Content-Length: 1270" 
[12]=> string(17) "Connection: close" 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM