Php 开发笔记相关

Summary: Author: 张亚飞 | 阅读时间: 3 minute read | Published: 2016-03-14
Filed under Categories: LinuxTags: Note,

Php 开发笔记相关


PHP 抢房



PHP 僵尸进程

  • 杀掉僵尸进程
kill -HUP `ps -A -ostat,ppid | grep -e '^[Zz]' | awk '{print $2}'`

参考

PHP多进程系列笔记(二)


PHP 自动加载


几种常用的 header 声明

  • header — 发送原生 HTTP 头

  • php.net

* 第一种 -- 标准写法
header('Content-type: application/json');
* 另一种 -- 旧版本,兼容 IE 6
header('Content-type: text/json');
header('Location: http://www.example.com/');

header('WWW-Authenticate: Negotiate');
header('WWW-Authenticate: NTLM', false)
  • 自动下载文件
// We'll be outputting a PDF
header('Content-type: application/pdf');

// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');

// The PDF source is in original.pdf
readfile('original.pdf');
  • 输出 utf-8
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: charset=utf-8'); # 短写法

php 对象数组相互转换

  • Converting an array/stdClass -> stdClass
$stdClass = json_decode(json_encode($booking));
  • Converting an array/stdClass -> array
$array = json_decode(json_encode($booking), true);

PHP 数组注意的地方:

  • 下载 PHP 文档源码:
$ wget https://www.php.net/distributions/manual/php_manual_zh.tar.gz
  • 过滤需要注意的数组函数:
Downloads/php-chunked-xhtml$ grep -r "注释" function.array*
function.array-change-key-case.html:  <h3 class="title">注释</h3>
function.array-diff-assoc.html:  <h3 class="title">注释</h3>
function.array-diff-key.html:  <h3 class="title">注释</h3>
function.array-diff-uassoc.html:  <h3 class="title">注释</h3>
function.array-diff-ukey.html:  <h3 class="title">注释</h3>
function.array-diff.html:  <h3 class="title">注释</h3>
function.array-fill.html:    <h3 class="title">注释</h3>
function.array-filter.html:  <h3 class="title">注释</h3>
function.array-intersect.html:  <h3 class="title">注释</h3>
function.array-key-exists.html:    <h3 class="title">注释</h3>
function.array-key-first.html:  <h3 class="title">注释</h3>
function.array-udiff-uassoc.html:  <h3 class="title">注释</h3>
function.array-udiff.html:  <h3 class="title">注释</h3>
function.array-unique.html:  <h3 class="title">注释</h3>
function.array.html:  <h3 class="title">注释</h3>

PHP 密码HASH加密方案

Password Hashing

  • password_hash: 对密码进行hash,得到散列值
  • password_verify: 对输入的密码进行校验,判断是否正确
  • password_get_info: 获取生成的hash值的信息,包括加密算法,相关加密参数等
  • password_needs_rehash: 检查一个hash值是否是使用特定算法及选项创建的

    $PtInfo = explode('/', pathinfo($_SERVER["SCRIPT_FILENAME"])['dirname']);
    //error_log(print_r($PtInfo, TRUE), 3, '/data/home/coam/Home/LoginWindows/Logs/ee.log');
    //error_log($PtInfo[5], 3, '/data/home/coam/Home/LoginWindows/Logs/ee.log');
//    $min_serveOptions['minApp']['groups'] = (require '/data/home/coam/CoamServer/' . $PtInfo[5] . '/public/MinifyGroupsConfig.php');
//    $min_serveOptions['minApp']['groups'] = (require BASE_COAM_SERVER_DIR ."/". $PtInfo[5] . '/public/MinifyGroupsConfig.php');
    $min_serveOptions['minApp']['groups'] = (require dirname(__DIR__) ."/../../../../". $PtInfo[5] . '/public/MinifyGroupsConfig.php');

PHP读取软件接ln 的相对父路径问题

PHP读取软连接下的PHP程序使用 DIR 获取的相对路径,获取的父级目录是源文件的父级目录,若想获取软连接的父级目录,应使用 $_SERVER[“SCRIPT_FILENAME”]来获取当前脚本文件绝句路径再拼接


关于 CGI, FastCGI, PHP-FPM, SPAWN-FCGI, Nginx 它们之间的关系

PHP OpCache

Comments

  • 牧马人 says: 2019-09-14 20:01:52

    I tried to add the class back but can’t seem to make it work..周盼盼

Cor-Ethan, the beverage → www.iirii.com