分类 PHP 下的文章

【7.2.18】
说明:此实例是在宝塔面板基础上进行安装扩展(原先我使用了apache2.8+php7.2.18+mysql5.6.27)

1.下载扩展

wget https://www.php.net/distributions/php-7.2.18.tar.gz

2.解压文件

tar -xvf php-7.2.18.tar.gz
3.打开目录

cd php-7.2.18/ext/fileinfo

4.直接执行以下命令 找不到 whice phpnize
/www/server/php/72/bin/phpize
返回:
Configuring for:
PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718
5.初始化配置
./configure --with-php-config=/www/server/php/72/bin/php-config
6.出现报错
make: * No targets specified and no makefile found. Stop.
virtual memory exhausted: Cannot allocate memory
显示内存不足 对于我的1GB小主机 使用不了 这时候需要创临时空间
解决办法:内存不足, 在linux下增加临时swap空间

参考《在linux下增加临时swap空间》
https://blog.csdn.net/qq_32642039/article/details/78070813?locationNum=7&fps=1

step 1:
  #sudo dd if=/dev/zero of=/home/swap bs=64M count=16
  注释:of=/home/swap,放置swap的空间; count的大小就是增加的swap空间的大小,64M就是块大小,这里是64MB,所以总共空间就是bs*count=1024MB.这里分配空间的时候需要一点时间,等待执行完毕。
  
step 2:
  # sudo mkswap /home/swap (可能会提示warning: don’t erase bootbits sectorson whole disk. Use -f to force,不用理会)
  注释:把刚才空间格式化成swap各式
step 3:
  #sudo swapon /home/swap
  注释:使刚才创建的swap空间

7.直接安装
make && make install

显示:

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:

  • add LIBDIR to the `LD_LIBRARY_PATH' environment variable
    during execution
  • add LIBDIR to the `LD_RUN_PATH' environment variable
    during linking
  • use the `-Wl,--rpath -Wl,LIBDIR' linker flag
  • have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for

more information, such as the ld(1) and ld.so(8) manual pages.

8.配置扩展

vi /www/server/php/72/etc/php.ini
添加以下:
extension = /www/server/php/72/lib/php/extensions/no-debug-non-zts-20170718/fileinfo.so

<?php

$chars=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
$n=3;
print_r(array_intersect_key($chars,array_flip(array_rand($chars,$n))));

?>

当月总天数

echo date('t');

计算当前的时间距离下一个月还有多少天

function less_day(){
    $month_big = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
    //现在的月份
    $date_month_old = (int)date('m',time());
    //下个月的月份
    $date_month_new = $date_month_old + 1;
    //下个月1号的时间戳
    $date_time_new = strtotime('1 '.$month_big[$date_month_new-1].' '.date('Y',time()));
    //今天的时间戳
    $date_time_old = strtotime(date('d',time()).' '.$month_big[$date_month_old-1].' '.date('Y',time()));
    //距下月剩余时间
    $time_new = ($date_time_new - $date_time_old)/24/60/60-1;
    return $time_new;
}
header("Content-type: text/html; charset=utf-8");
echo '今天是:'.date('Y-m-d',time()).'<br/>';
echo '距离下个月还有:'.less_day().'天';

以上内容转载自https://bobjin.com/blog/view/4994c03c126159ba64788a0be6d59d6c.html 尊重原作者的劳动成果