get_ip_address
1 |
(string) get_ip_address() |
Description
函数检查是否在(透明)代理后面,并返回找到的IP地址。
1 |
(string) get_ip_address() |
函数检查是否在(透明)代理后面,并返回找到的IP地址。
1 2 3 4 5 |
$phar = new Phar("joefom.phar"); $phar->buildFromDirectory(dirname(__FILE__)); // 从当前文件夹打包 $phar->setStub($phar->createDefaultStub("index.php")); // 入口文件是index.php $phar->compressFiles(Phar::GZ); |
这样一个叫做 joefom.phar 的Phar包就打包成功了。
先从编译安装php7.2开始
一些必要的软件
1 |
# yum install libxml2 libxml2-devel curl curl-devel libpng-devel libjpeg-devel pcre-devel autoconf |
来到PHP源码下 :
1 |
# ./configure --prefix=/usr/local/php72 --with-gd --with-iconv --with-mcrypt --with-pdo-mysql=shared,mysqlnd --with-zlib --enable-xml --enable-mbstring --enable-pcntl --with-curl |
然后 make && make install
1 2 3 4 5 6 7 8 9 |
function onlineStatus($addr,$port=80) { $status = array("OFFLINE", "ONLINE"); $handle = fsockopen($addr,$port,$errno,$errstr,2); if($handle) return $status[1]; else return $status[0]; } |
调用:
1 |
echo onlineStatus('ssl://www.baidu.com',443); |
返回值需要Boolean的自己改。
1 2 3 4 5 |
$ docker pull centos ... $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos latest e934aafc2206 7 weeks ago 199MB |
先创建一个临时容器,就取名叫tmp吧
1 |
$ docker run --privileged -it --name tmp centos:latest /usr/sbin/init |
这时容器已经创建好了,但是因为没有设置bash,所以会卡在当前会话。我们另开一个会话
我尽可能的使用基于alpine的镜像
Dockerfile参考:
Docker官方: https://hub.docker.com/_/php/
阿里云:https://dev.aliyun.com/detail.html?repoId=1250
1 2 3 4 5 6 |
$ docker pull php:7.2.0-fpm-alpine3.6 $ docker run -d --rm --name fpm php:7.2.4-fpm-alpine3.7 #启动容器,并后台运行 db2de87189f30c3592684531ef7cf4d0b9fbaf8bace66b9db496aebb8edab318 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES db2de87189f3 php:7.2.4-fpm-alpine3.7 "docker-php-entrypoi…" 2 minutes ago Up 2 minutes 9000/tcp fpm |
可以在PORTS下方看到端口默认是9000
先拉取个阿里云的镜像
https://dev.aliyun.com/detail.html?repoId=1250
至于docker安装,镜像源设置,请参考《Linux上yum安装docker》
1 2 3 4 |
$ docker pull php:7.2.4-cli-alpine3.7 $ vi code/php/index.php <?php echo 'hi joefom'; |
1 2 |
$ docker run -it --rm -v /home/joefom/code/php/:/abc php:7.2.4-cli-alpine3.7 php /abc/index.php hi joefom |
PHP在Apache中一共有三种工作方式:CGI模式、Apache模块DLL、FastCGI模式
PHP 在 Apache 2中的 CGI模式。编辑Apache 配置文件httpd.conf 如下:
# PHP4 版写法
1 2 3 |
ScriptAlias /php/ "D:/php/" AddType application/x-httpd-php .php Action application/x-httpd-php "/php/php.exe" |
# PHP5 版写法
1 2 3 |
ScriptAlias /php/ "D:/php/" AddType application/x-httpd-php .php Action application/x-httpd-php "/php/php-cgi.exe" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
function triggerRequest($url,$post_data = [],$cookie = []) { $method = 'GET'; $url_array = parse_url($url); $url_array['port'] = $url_array['scheme'] == 'https'?443:80; $url_array['scheme'] = $url_array['scheme'] == 'https'?'ssl://':'tcp://'; $url_array['query'] = isset($url_array['query'])?'?'.$url_array['query']:''; $url_array['path'] = isset($url_array['path'])?$url_array['path']:'/'; $fp = fsockopen($url_array['scheme'].$url_array['host'].':'.$url_array['port'].$url_array['path'].$url_array['query'],$url_array['port'],$errno,$errstr,30); if(!$fp) return FALSE; if(!empty($post_data)) $method = 'POST'; $header = $method." ".$url_array['path']." HTTP/1.1\r\n"; $header .= "Host: ".$url_array['host']."\r\n"; //HTTP 1.1 Host域不能省略 $header .= "Connection: Close\r\n\r\n"; if(!empty($cookie)){ $_cookie = strval(NULL); foreach($cookie as $k => $v){ $_cookie .= $k."=".$v."; "; } $cookie_str = "Cookie: " . base64_encode($_cookie) ." \r\n";//传递Cookie $header .= $cookie_str; } if(!empty($post_data)){ $_post = strval(NULL); foreach($post_data as $k => $v){ $_post .= $k."=".$v."&"; } $post_str = "Content-Type: application/x-www-form-urlencoded\r\n";//POST数据 $post_str .= "Content-Length: ". strlen($_post) ." \r\n";//POST数据的长度 $post_str .= $_post."\r\n\r\n "; //传递POST数据 $header .= $post_str; } fwrite($fp, $header); //我们不关心服务器返回 /*while(!feof($fp)) { echo fgets($fp,128); }*/ fclose($fp); return true; } |