GVKun编程网logo

PHP实现的浏览器检查类 phpstorm浏览器设置 php 模拟浏览器 php输出图片到浏览

1

想了解PHP实现的浏览器检查类phpstorm浏览器设置php模拟浏览器php输出图片到浏览的新动态吗?本文将为您提供详细的信息,此外,我们还将为您介绍关于12.21php-fpm的pool12.22

想了解PHP实现的浏览器检查类 phpstorm浏览器设置 php 模拟浏览器 php输出图片到浏览的新动态吗?本文将为您提供详细的信息,此外,我们还将为您介绍关于12.21 php-fpm的pool 12.22 php-fpm慢执行日志 12.23 open_basedir 12.24 php-fpm进程管理、5、PHP-将浮点数转为整数 php 浮点数比较 php 浮点数精度 php 浮点数格式、Brew 安装 php,但“php -v”返回 MacOS 原生 php 的信息、file_get_contents('php://input') 不适用于 Laravel+Octane / Swoole PHP 代码使用 PHP-FPM使用 Octane+Swoole的新知识。

本文目录一览:

PHP实现的浏览器检查类 phpstorm浏览器设置 php 模拟浏览器 php输出图片到浏览

PHP实现的浏览器检查类 phpstorm浏览器设置 php 模拟浏览器 php输出图片到浏览

本文实例讲述了php实现的浏览器检查类。分享给大家供大家参考,具体如下:

UA  = getenv(HTTP_USER_AGENT);
  $preparens = "";
  $parens = "";
  $i = strpos($this->UA,"(");
  if ($i >= 0)  {
    $preparens = trim(substr($this->UA,0,$i));
    $parens = substr($this->UA,$i+1,strlen($this->UA));
    $j = strpos($parens,")");
    if($j>=0) {
     $parens = substr($parens,0,$j);
    }
  }
  else  {
    $preparens = $this->UA;
  }
  $browVer = $preparens;
  $token = trim(strtok($parens,";"));
  while($token)  {
    if($token=="compatible") {
    }
    elseif(preg_match("/MSIE/i","$token")) {
     $browVer = $token;
    }
    elseif(preg_match("/Opera/i","$token")) {
     $browVer = $token;
    }
    elseif(preg_match("/X11/i","$token") || preg_match("/SunOS/i","$token") || preg_match ("/Linux/i","$token")) {
     $this->PLATFORM  = "Unix";
    }
    elseif(preg_match("/Win/i","$token")) {
     $this->PLATFORM  = $token;
    }
    elseif(preg_match("/Mac/i","$token") || preg_match("/PPC/i","$token")) {
     $this->PLATFORM  = $token;
    }
    $token = strtok(";");
  }
  $msieIndex = strpos($browVer,"MSIE");
  if($msieIndex >= 0)  {
    $browVer = substr($browVer,$msieIndex,strlen($browVer));
  }
  $leftover  = "";
  if(substr($browVer,0,strlen("Mozilla")) == "Mozilla")  {
    $this->BROWSER = "Netscape";
    $leftover=substr($browVer,strlen("Mozilla")+1,strlen($browVer));
  }
  elseif(substr($browVer,0,strlen("Lynx")) == "Lynx")  {
    $this->BROWSER = "Lynx";
    $leftover=substr($browVer,strlen("Lynx")+1,strlen($browVer));
  }
  elseif(substr($browVer,0,strlen("MSIE")) == "MSIE") {
    $this->BROWSER = "IE";
    $leftover=substr($browVer,strlen("MSIE")+1,strlen($browVer));
  }
  elseif(substr($browVer,0,strlen("Microsoft Internet Explorer")) == "Microsoft Internet Explorer")  {
    $this->BROWSER = "IE";
    $leftover=substr($browVer,strlen("Microsoft Internet Explorer")+1,strlen($browVer));
  }
  elseif(substr($browVer,0,strlen("Opera")) == "Opera")  {
    $this->BROWSER = "Opera";
    $leftover=substr($browVer,strlen("Opera")+1,strlen($browVer));
  }
  $leftover = trim($leftover);
  $i=strpos($leftover," ");
  if($i > 0)  {
    $this->VERSION = substr($leftover,0,$i);
  }
  else  {
    $this->VERSION = $leftover;
  }
  $j = strpos($this->VERSION,".");
  if($j >= 0)  {
    $this->MAJORVER = substr($this->VERSION,0,$j);
    $this->MINORVER = substr($this->VERSION,$j+1,strlen($this->VERSION));
  }
  else  {
    $this->MAJORVER = $this->VERSION;
  }
 }
}
//测试程序开始
$test=new browserdetector;
echo $test-&gt;UA."<br>";
echo $test-&gt;BROWSER."<br>";
echo $test-&gt;PLATFORM."<br>";
echo $test-&gt;VERSION."<br>";
echo $test-&gt;MAJORVER."<br>";
echo $test-&gt;MINORVER."<br>";
?&gt;

登录后复制

更多关于PHP相关内容感兴趣的读者可查看本站专题:《php文件操作总结》、《PHP运算与运算符用法总结》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php操作office文档技巧总结(包括word,excel,access,ppt)》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

以上就介绍了PHP实现的浏览器检查类,包括了浏览器,php方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

12.21 php-fpm的pool 12.22 php-fpm慢执行日志 12.23 open_basedir 12.24 php-fpm进程管理

12.21 php-fpm的pool 12.22 php-fpm慢执行日志 12.23 open_basedir 12.24 php-fpm进程管理

12.21 php-fpm的pool

为了避免因多站点使用同一个pool时因一个站点故障导致pool出问题,进而影响使用同一个pool的其他站点的正常运行,要对每个站点配置一个单独的pool。

为php-fpm增加pool

[root@cham002 cham.com]# cd /usr/local/php-fpm/etc/
[root@cham002 etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php.ini
[root@cham002 etc]# cat php-fpm.conf
[global]
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
[www]
#listen = /tmp/php-fcgi.sock
listen = 127.0.0.1:9000
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
[root@cham002 etc]# vi !$
vi php-fpm.conf

[champin.com]
#listen = /tmp/champin.sock
listen = 127.0.0.1:9000
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024

语法检测:

[root@cham002 etc]# /usr/local/php-fpm/sbin/php-fpm -t
[09-Jan-2018 00:36:35] ERROR: [pool champin.com] unable to set listen address as it''s already used in another pool ''www''
[09-Jan-2018 00:36:35] ERROR: failed to post process the configuration
[09-Jan-2018 00:36:35] ERROR: FPM initialization failed

原因是我以为名字不对,后来换了名字还是不行,仔细看配置文件发现原因

[root@cham002 etc]# /usr/local/php-fpm/sbin/php-fpm -t
[09-Jan-2018 00:45:20] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
[root@cham002 etc]# /etc/init.d/php-fpm reload
Reload service php-fpm  done

[root@cham002 etc]# ps aux |grep php-fpm
root      6251  0.5  0.4 227212  4980 ?        Ss   00:49   0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm   6252  0.0  0.4 227152  4712 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6253  0.0  0.4 227152  4712 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6254  0.0  0.4 227152  4712 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6255  0.0  0.4 227152  4712 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6256  0.0  0.4 227152  4716 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6257  0.0  0.4 227152  4716 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6258  0.0  0.4 227152  4716 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6259  0.0  0.4 227152  4720 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6260  0.0  0.4 227152  4720 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6261  0.0  0.4 227152  4720 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6262  0.0  0.4 227152  4720 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6263  0.0  0.4 227152  4720 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6264  0.0  0.4 227152  4720 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6265  0.0  0.4 227152  4720 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6266  0.0  0.4 227152  4720 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6267  0.0  0.4 227152  4720 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6268  0.0  0.4 227152  4720 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6269  0.0  0.4 227152  4720 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6270  0.0  0.4 227152  4720 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6271  0.0  0.4 227152  4720 ?        S    00:49   0:00 php-fpm: pool www
php-fpm   6272  0.0  0.4 227152  4716 ?        S    00:49   0:00 php-fpm: pool champ
php-fpm   6273  0.0  0.4 227152  4716 ?        S    00:49   0:00 php-fpm: pool champ
php-fpm   6274  0.0  0.4 227152  4716 ?        S    00:49   0:00 php-fpm: pool champ
php-fpm   6275  0.0  0.4 227152  4720 ?        S    00:49   0:00 php-fpm: pool champ
php-fpm   6276  0.0  0.4 227152  4724 ?        S    00:49   0:00 php-fpm: pool champ
php-fpm   6277  0.0  0.4 227152  4724 ?        S    00:49   0:00 php-fpm: pool champ
php-fpm   6278  0.0  0.4 227152  4724 ?        S    00:49   0:00 php-fpm: pool champ
php-fpm   6279  0.0  0.4 227152  4724 ?        S    00:49   0:00 php-fpm: pool champ
php-fpm   6280  0.0  0.4 227152  4724 ?        S    00:49   0:00 php-fpm: pool champ
php-fpm   6281  0.0  0.4 227152  4724 ?        S    00:49   0:00 php-fpm: pool champ
php-fpm   6282  0.0  0.4 227152  4724 ?        S    00:49   0:00 php-fpm: pool champ
php-fpm   6283  0.0  0.4 227152  4724 ?        S    00:49   0:00 php-fpm: pool champ
php-fpm   6284  0.0  0.4 227152  4724 ?        S    00:49   0:00 php-fpm: pool champ
php-fpm   6285  0.0  0.4 227152  4724 ?        S    00:49   0:00 php-fpm: pool champ
php-fpm   6286  0.0  0.4 227152  4724 ?        S    00:49   0:00 php-fpm: pool champ
php-fpm   6287  0.0  0.4 227152  4724 ?        S    00:49   0:00 php-fpm: pool champ
php-fpm   6288  0.0  0.4 227152  4724 ?        S    00:49   0:00 php-fpm: pool champ
php-fpm   6289  0.0  0.4 227152  4724 ?        S    00:49   0:00 php-fpm: pool champ
php-fpm   6290  0.0  0.4 227152  4724 ?        S    00:49   0:00 php-fpm: pool champ
php-fpm   6291  0.0  0.4 227152  4728 ?        S    00:49   0:00 php-fpm: pool champ
root      6293  1.0  0.0 112680   976 pts/1    R+   00:49   0:00 grep --color=auto php-fpm

为站点配置pool

[root@cham002 etc]# cd /usr/local/nginx/conf/vhost/
[root@cham002 vhost]# ls
aaa.com.conf  load.conf  proxy.conf  ssl.conf  test.com.conf
[root@cham002 vhost]# vim aaa.com.conf 

server
{
    listen 80 default_server;
    server_name aaa.com;
    index index.html index.htm index.php;
    root /data/wwwroot/default;
 location ~ \.php$
    {
        include fastcgi_params;
        fastcgi_pass unix:/tmp/champ.sock;
       #fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /data/wwwroot/default$fastcgi_script_name;
    }

}

说明: 把fastcgi_pass地址改为和php-fpm.conf中一样的地址就可以。

 

添加php-fpm.conf子配置文件

为了便于管理,可以将php-fpm中的每个pool单独进行管理。进行如下操作,添加php-fpm子配置文件:

[root@cham002 vhost]# cd /usr/local/php-fpm/etc/
[root@cham002 etc]# vim php-fpm.conf
[global]
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
include = etc/php-fpm.d/*.conf

说明: 在全局变量版块添加参数“include = etc/php-fpm.d/*.conf”。然后可以清除php-fpm配置文件中其他参数,再到php-fpm.d目录下进行单独设置。

[root@cham002 vhost]# cd /usr/local/php-fpm/etc/
[root@cham002 etc]# mkdir php-fpm.d
[root@cham002 etc]# cd php-fpm.d/
[root@cham002 php-fpm.d]# vim www.conf
[www]
listen = /tmp/php-fcgi.sock
#listen = 127.0.0.1:9000
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
[root@cham002 php-fpm.d]# ls
www.conf

[root@cham002 php-fpm.d]# vim champ.conf
[champ]
listen = /tmp/champ.sock
#listen = 127.0.0.1:9000
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
[root@cham002 php-fpm.d]# ls
champ.conf  www.conf


[root@cham002 php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t
[09-Jan-2018 01:20:26] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful

[root@cham002 php-fpm.d]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done


[root@cham002 php-fpm.d]# ps aux |grep php-fpm
root      6508  1.5  0.4 227240  4988 ?        Ss   01:26   0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm   6509  0.0  0.4 227180  4720 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6510  0.0  0.4 227180  4720 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6511  0.0  0.4 227180  4720 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6512  0.0  0.4 227180  4720 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6513  0.0  0.4 227180  4724 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6514  0.0  0.4 227180  4724 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6515  0.0  0.4 227180  4724 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6516  0.0  0.4 227180  4724 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6517  0.0  0.4 227180  4724 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6518  0.0  0.4 227180  4724 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6519  0.0  0.4 227180  4724 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6520  0.0  0.4 227180  4724 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6521  0.0  0.4 227180  4724 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6522  0.0  0.4 227180  4724 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6523  0.0  0.4 227180  4724 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6524  0.0  0.4 227180  4728 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6525  0.0  0.4 227180  4728 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6526  0.0  0.4 227180  4728 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6527  0.0  0.4 227180  4728 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6528  0.0  0.4 227180  4728 ?        S    01:26   0:00 php-fpm: pool champ
php-fpm   6529  0.0  0.4 227180  4724 ?        S    01:26   0:00 php-fpm: pool www
php-fpm   6530  0.0  0.4 227180  4724 ?        S    01:26   0:00 php-fpm: pool www
php-fpm   6531  0.0  0.4 227180  4724 ?        S    01:26   0:00 php-fpm: pool www
php-fpm   6532  0.0  0.4 227180  4724 ?        S    01:26   0:00 php-fpm: pool www
php-fpm   6533  0.0  0.4 227180  4728 ?        S    01:26   0:00 php-fpm: pool www
php-fpm   6534  0.0  0.4 227180  4728 ?        S    01:26   0:00 php-fpm: pool www
php-fpm   6535  0.0  0.4 227180  4728 ?        S    01:26   0:00 php-fpm: pool www
php-fpm   6536  0.0  0.4 227180  4728 ?        S    01:26   0:00 php-fpm: pool www
php-fpm   6537  0.0  0.4 227180  4728 ?        S    01:26   0:00 php-fpm: pool www
php-fpm   6538  0.0  0.4 227180  4728 ?        S    01:26   0:00 php-fpm: pool www
php-fpm   6539  0.0  0.4 227180  4728 ?        S    01:26   0:00 php-fpm: pool www
php-fpm   6540  0.0  0.4 227180  4732 ?        S    01:26   0:00 php-fpm: pool www
php-fpm   6541  0.0  0.4 227180  4732 ?        S    01:26   0:00 php-fpm: pool www
php-fpm   6542  0.0  0.4 227180  4732 ?        S    01:26   0:00 php-fpm: pool www
php-fpm   6543  0.0  0.4 227180  4732 ?        S    01:26   0:00 php-fpm: pool www
php-fpm   6544  0.0  0.4 227180  4732 ?        S    01:26   0:00 php-fpm: pool www
php-fpm   6545  0.0  0.4 227180  4732 ?        S    01:26   0:00 php-fpm: pool www
php-fpm   6546  0.0  0.4 227180  4732 ?        S    01:26   0:00 php-fpm: pool www
php-fpm   6547  0.0  0.4 227180  4732 ?        S    01:26   0:00 php-fpm: pool www
php-fpm   6548  0.0  0.4 227180  4732 ?        S    01:26   0:00 php-fpm: pool www
root      6550  0.0  0.0 112680   976 pts/1    R+   01:26   0:00 grep --color=auto php-fpm


配置完成后使用ps查看php-fpm进程信息。

12.22 php-fpm的慢执行日志

开启慢执行日志:

[root@cham002 php-fpm.d]# vim www.conf 

[www]
listen = /tmp/php-fcgi.sock
#listen = 127.0.0.1:9000
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
request_slowlog_timeout = 1
#当请求超过1秒开始记录日志
slowlog = /usr/local/php-fpm/var/log/www-slow.log
#日志存放路径

试验

在使用www pool的站点添加文件: 

[root@cham002 php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t
[09-Jan-2018 01:31:57] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful

[root@cham002 php-fpm.d]# /etc/init.d/php-fpm reload
Reload service php-fpm  done

[root@cham002 php-fpm.d]# ls /usr/local/php-fpm/var/log/www-slow.log
/usr/local/php-fpm/var/log/www-slow.log

[root@cham002 php-fpm.d]# vim /data/wwwroot/test.com/sleep.php

<?php
 echo "test slow log";
sleep(2);
echo "done";
?>

 试一下

[root@cham002 php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.12.1</center>
</body>
</html>
[root@cham002 php-fpm.d]# cat /usr/local/nginx/conf/vhost/test.com.conf 
server
{
    listen 80;
#报502的错误,查看配置文件,发现监听的地址被注重掉了
[root@cham002 php-fpm.d]# cat /usr/local/nginx/conf/vhost/test.com.conf 
server
{
    listen 80;
    server_name test.com test2.com test3.com;
    index index.html index.htm index.php;
    root /data/wwwroot/test.com;
    if ($host != ''test.com'' ) {
        rewrite  ^/(.*)$  http://test.com/$1  permanent;
    }
   # location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
   # {
   #       expires      7d;
   #       access_log off;
   # }
location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$
{
    expires 7d;
    valid_referers none blocked server_names  *.test.com ;
    if ($invalid_referer) {
        return 403;
    }
    access_log off;
}


    location ~ .*\.(js|css)$
    {
          expires      12h;
          access_log off;
    }
    location /admin/
    {
       allow 127.0.0.1;
       allow 192.168.230.135;
       deny all;
    }

    location ~ .*(upload|image)/.*\.php$
    {
        deny all;
    }
    
    if ($http_user_agent ~ ''Spider/3.0|YoudaoBot|Tomato'')
    {
      return 403;
    }

    location ~ \.php$
    {
        include fastcgi_params;
        #fastcgi_pass unix:/tmp/php-fcgi.sock;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name;
    }



    access_log /tmp/test.com.log cham;
}

[root@cham002 php-fpm.d]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@cham002 php-fpm.d]#  /usr/local/nginx/sbin/nginx -s reload


[root@cham002 php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php
test slow logdone

Reload service php-fpm  done


[root@cham002 php-fpm.d]# cat /usr/local/php-fpm/var/log/www-slow.log 
##查看日志!!!!!
[09-Jan-2018 01:50:17]  [pool www] pid 6700
script_filename = /data/wwwroot/test.com/sleep.php
[0x00007f98c94b02f8] sleep() /data/wwwroot/test.com/sleep.php:3

日志中表明详细信息

说明:一般会写成2秒,多数php脚本都会超过1秒

 

12.23 php-fpm中指定open_basedir

当一台服务器跑多个站点时,使用open_basedir限定各个站点所能访问的服务器上的目录的范围。在php-fpm服务中,可以针对每个pool设定open _ basedir。

核心配置参数:

[root@cham002 php-fpm.d]# vim www.conf 

[www]
listen = /tmp/php-fcgi.sock
#listen = 127.0.0.1:9000
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
request_slowlog_timeout = 1
slowlog = /usr/local/php-fpm/var/log/www-slow.log
php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/


[root@cham002 php-fpm.d]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done
[root@cham002 php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php -I
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Mon, 08 Jan 2018 18:05:28 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.30

[root@cham002 php-fpm.d]# vi /usr/local/php-fpm/etc/php.ini

[root@cham002 php-fpm.d]# grep error_log /usr/local/php-fpm/etc/php.ini
; server-specific log, STDERR, or a location specified by the error_log
; Set maximum length of log_errors. In error_log information about the source is
;error_log = php_errors.log
;error_log = syslog
error_log = /usr/local/php-fpm/var/log/php_errors.log
; OPcache error_log file name. Empty string assumes "stderr".
;opcache.error_log=
[root@cham002 php-fpm.d]# ls /usr/local/php-fpm/var/log/
php-fpm.log   www-slow.log  
[root@cham002 php-fpm.d]# vim www.conf 故意写错地址
[root@cham002 php-fpm.d]# touch /usr/local/php-fpm/var/log/php_errors.log
[root@cham002 php-fpm.d]# chmod 777 /usr/local/php-fpm/var/log/php_errors.log
[root@cham002 php-fpm.d]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done

[root@cham002 php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php
No input file specified.
[root@cham002 php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php -I
HTTP/1.1 404 Not Found
Server: nginx/1.12.1
Date: Mon, 08 Jan 2018 18:17:50 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.30

[root@cham002 php-fpm.d]# cat /usr/local/php-fpm/var/log/php_errors.log
[08-Jan-2018 18:17:44 UTC] PHP Warning:  Unknown: open_basedir restriction in effect. File(/data/wwwroot/test.com/3.php) is not within the allowed path(s): (/data/wwwroot/etest.com:/tmp/) in Unknown on line 0
[08-Jan-2018 18:17:44 UTC] PHP Warning:  Unknown: failed to open stream: Operation not permitted in Unknown on line 0
[08-Jan-2018 18:17:50 UTC] PHP Warning:  Unknown: open_basedir restriction in effect. File(/data/wwwroot/test.com/3.php) is not within the allowed path(s): (/data/wwwroot/etest.com:/tmp/) in Unknown on line 0
[08-Jan-2018 18:17:50 UTC] PHP Warning:  Unknown: failed to open stream: Operation not permitted in Unknown on line 0

改正之后再来测试
[root@cham002 php-fpm.d]# vim www.conf 

[root@cham002 php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php -I
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Mon, 08 Jan 2018 18:21:54 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.30


 

12.24 php-fpm进程管理

php-fpm中pool配置参数解析:

[root@cham002 php-fpm.d]# cat www.conf 
[www]
listen = /tmp/php-fcgi.sock
#listen = 127.0.0.1:9000
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
;定义进程启动方式(dynamic表示动态,static表示静态)
;只有此处设置为dynamic,下面的配置才生效
pm.max_children = 50
;最多可启动的子进程数量
pm.start_servers = 20
;设定初始启动的进程数量
pm.min_spare_servers = 5
;表示php-fpm空闲时最少要有几个子进程
pm.max_spare_servers = 35
;表示php-fpm空闲时最多要有几个子进程
pm.max_requests = 500
;表示一个子进程最多可接受多少个请求
rlimit_files = 1024
;表示每个子进程打开的多少个文件句柄
request_slowlog_timeout = 1
;当请求超过1秒开始记录日志
slowlog = /usr/local/php-fpm/var/log/www-slow.log
;日志存放地址
php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/

 

5、PHP-将浮点数转为整数 php 浮点数比较 php 浮点数精度 php 浮点数格式

5、PHP-将浮点数转为整数 php 浮点数比较 php 浮点数精度 php 浮点数格式

1、使用强制类型转换

首先PHP支持如下所示的数据类型:

<span>1. </span>Integer    (整数)
<span>2. </span>Float      (浮点数)
<span>3. </span>String     (字符串)
<span>4. </span>Boolean    (布尔值)
<span>5. </span>Array      (数组)
<span>6. </span>Object     (对象)
登录后复制

此外还有两个特殊的类型:NULL(空)、resource(资源)。

注:
1. 没有被赋值、已经被重置或者被赋值为特殊值NULL的变量就是NULL类型的变量。
2. 特定的内置函数(例如数据库函数)将返回resource类型的变量。

接着可以使用类似C语言的强制类型转换,例如

<span><?php </span><span>$a</span>=<span>6.66666</span>;
<span>$b</span>=(integer)<span>$a</span>;
<span>echo</span><span>$b</span>;</span>
登录后复制

将输出一个6,直接舍去了小数部分

立即学习“PHP免费学习笔记(深入)”;

2、使用float floor ( float value) 函数

舍去法取整,返回不大于 value 的下一个整数,将 value 的小数部分舍去取整。floor() 返回的类型仍然是 float,因为float 值的范围通常比 integer 要大。

echo <span>floor</span>(<span>4.3</span>);   <span>// 输出4 </span>
echo <span>floor</span>(<span>9.999</span>); <span>// 输出9</span>
登录后复制

3、使用float ceil ( float value) 函数

进一法取整,返回不小于 value 的下一个整数,value 如果有小数部分则进一位。ceil() 返回的类型仍然是 float,因为float 值的范围通常比 integer 要大。

echo <span>ceil</span>(<span>4.3</span>);    <span>// 输出5 </span>
echo <span>ceil</span>(<span>9.999</span>);  <span>// 输出10</span>
登录后复制

4、使用float round ( float val [, int precision])函数

对浮点数进行四舍五入,返回将 val 根据指定精度 precision(十进制小数点后数字的数目)进行四舍五入的结果。precision 也可以是负数或零(默认值)。

echo <span>round</span>(<span>3.4</span>);         <span>// 输出3 </span>
echo <span>round</span>(<span>3.5</span>);         <span>// 输出4 </span>
echo <span>round</span>(<span>3.6</span>);         <span>// 输出4 </span>
echo <span>round</span>(<span>3.6</span>, <span>0</span>);      <span>// 输出4 </span>
echo <span>round</span>(<span>1.95583</span>, <span>2</span>);  <span>// 输出1.96 </span>
echo <span>round</span>(<span>1241757</span>, -<span>3</span>); <span>// 输出1242000 </span>
echo <span>round</span>(<span>5.045</span>, <span>2</span>);    <span>// 输出5.04 </span>
echo <span>round</span>(<span>5.055</span>, <span>2</span>);    <span>// 输出5.06</span>
登录后复制
'').addClass(''pre-numbering'').hide(); $(this).addClass(''has-numbering'').parent().append($numbering); for (i = 1; i '').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了5、PHP-将浮点数转为整数,包括了php,浮点数方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Brew 安装 php,但“php -v”返回 MacOS 原生 php 的信息

Brew 安装 php,但“php -v”返回 MacOS 原生 php 的信息

删除系统二进制文件通常不是一个好主意。相反,您可以在 ~/.zshrc 文件中添加别名。在文件末尾添加:

alias php="/usr/local/bin/php"
,

解决方案是将其放入 ~/.bash-profile

export PATH=/usr/local/bin:$PATH

重启电脑,它准备好了,现在当我php -v

PHP 8.0.3 (cli) (built: Mar  4 2021 20:45:17) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.3,Copyright (c) Zend Technologies
    with Zend OPcache v8.0.3,Copyright (c),by Zend Technologies

file_get_contents('php://input') 不适用于 Laravel+Octane / Swoole PHP 代码使用 PHP-FPM使用 Octane+Swoole

file_get_contents('php://input') 不适用于 Laravel+Octane / Swoole PHP 代码使用 PHP-FPM使用 Octane+Swoole

如何解决file_get_contents(''php://input'') 不适用于 Laravel+Octane / Swoole PHP 代码使用 PHP-FPM使用 Octane+Swoole?

我正在从 Laravel 8 迁移到 Laravel 8 + Octane / Swoole。一切正常,但 PHP://input 始终为空。另外,我检查 $_POST 和 $_SERVER 值。

file_get_contents(''PHP://input'') 被 AWS SNS Message Validator 使用。

阅读 PHP://input 的任何替代方案?

PHP 代码

echo "PHP://input: ".file_get_contents(''PHP://input'');

使用 PHP-FPM

$ curl -i -X POST --data "dataaaa" https://example.com/aws/sns/webhook
PHP://input: dataaaa

使用 Octane+Swoole

$ curl -i -X POST --data "dataaaa" https://example.com/aws/sns/webhook
PHP://input:

解决方法

问题

[+] Building 10.5s (9/9) FINISHED => [internal] load build definition from Dockerfile 0.2s => => transferring dockerfile: 133B 0.0s => [internal] load .dockerignore 0.2s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/python:3.9 0.9s => [auth] library/python:pull token for registry-1.docker.io 0.0s => CACHED [1/3] FROM docker.io/library/python:3.9@sha256:acb4e43d0c66c168e72ceaba5913cde472e4a17017cec9346969c9725a1fea94 0.0s => [internal] load build context 0.1s => => transferring context: 12.01kB 0.0s => [2/3] ADD main.py . 0.5s => [3/3] RUN pip install pillow 6.9s => exporting to image 1.5s => => exporting layers 1.2s => => writing image sha256:95e56740a3427899906e9c6522198f5d749fd13870450b046a2bd874b3a04548 0.0s => => naming to docker.io/library/background-revolution 在 Swoole 上不可用。始终是同一个运行进程。

解决方案:PSR-7 请求

php://input

当然,对于辛烷值,Laravel PSR-7 requests 需要 use Psr\Http\Message\RequestInterface; public function sesSubscriptionWebhook(RequestInterface $request) { // $input = file_get_contents(''php://input''); // dont work on swoole $input = $request->getBody(); } symfony/psr-http-message-bridge

此外,如果您的问题与 AWS SES 相关,您需要将 nyholm/psr7 更改为 Message::fromRawPostData()

今天关于PHP实现的浏览器检查类 phpstorm浏览器设置 php 模拟浏览器 php输出图片到浏览的分享就到这里,希望大家有所收获,若想了解更多关于12.21 php-fpm的pool 12.22 php-fpm慢执行日志 12.23 open_basedir 12.24 php-fpm进程管理、5、PHP-将浮点数转为整数 php 浮点数比较 php 浮点数精度 php 浮点数格式、Brew 安装 php,但“php -v”返回 MacOS 原生 php 的信息、file_get_contents('php://input') 不适用于 Laravel+Octane / Swoole PHP 代码使用 PHP-FPM使用 Octane+Swoole等相关知识,可以在本站进行查询。

本文标签: