2021年5月

PHP修改upload_max_filesize无效的问题

前言

PHP做插件的过程中,发现上传的zip文件,大于8M的会直接中断传输,印象中我已经改过了upload_max_filesize设置为300M了呀。

解决

修改php.ini中的upload_max_filesize为300M后,还要检查下:post_max_size,这玩意儿一般会忘记,也将这个设置为300M后解决问题。

附加配置

file_uploads = On

upload_max_filesize = 300M
post_max_size=300M

max_file_uploads = 20

附加phperror.log

[13-May-2021 09:17:02] NOTICE: fpm is running, pid 1
[13-May-2021 09:17:02] NOTICE: ready to handle connections
NOTICE: PHP message: PHP Warning:  POST Content-Length of 8630132 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
NOTICE: PHP message: PHP Warning:  POST Content-Length of 8630132 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
NOTICE: PHP message: PHP Warning:  POST Content-Length of 8630132 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
NOTICE: PHP message: PHP Warning:  POST Content-Length of 8630132 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
NOTICE: PHP message: PHP Warning:  POST Content-Length of 8630132 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
NOTICE: PHP message: PHP Warning:  POST Content-Length of 8630132 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
[13-May-2021 09:39:11] NOTICE: Finishing ...
[13-May-2021 09:39:11] NOTICE: exiting, bye-bye!
[13-May-2021 09:39:14 UTC] PHP Warning:  Module "redis" is already loaded in Unknown on line 0
[13-May-2021 09:39:14] NOTICE: fpm is running, pid 1
[13-May-2021 09:39:14] NOTICE: ready to handle connections

[ docker]PHP8开启zip支持

前言

最近在整理推特的推文批量删除的功能,就是支持删除所有推文的功能,其中有用到压缩解压的类,综合考虑,打算使用linux中的libzip-dev依赖,为此搜索了好多地方,网上的介绍不尽相同,我这里将我真实能用的配置方式发出来,以供后续如果要继续操作的时候,可以用的上。

安装

因为我是在php4docker中使用的,所以我首先就是要查对应的extension怎么装,查看官方文档Installation
很简单,有个老哥已经说了要怎么操作了

首先是安装zlib1g-dev,libzip-dev,zip,其中zlib1g需要指定稍低一点的版本,我这里指定了1:1.2.8.dfsg-5,否则则会无法通过依赖。

之后是安装docker-php-ext,看下面代码
docker-php-ext-install mysqli pdo pdo_mysql zip

配置

这样镜像就整理好了,接下来修改php配置文件,如果不修改的话,还是会提示zipArchive找不到
php.ini增加extension = zip.so,之后重启php即可。

docker-compose中重新编译运行

直接使用build命令:docker-compose build;

测试

    private function unzip($filepath){
        if (empty($filepath)) {
            return false;
        }
        $zip = new ZipArchive();
        if ($zip->open($filepath) === true) {
            $zip->extractTo("/tmp/".$this->widget('Widget_User')->uid,"twitter.js");
            $zip->close();
            return true;
        }
        else{
            return false;
        }
    }

参考:

  1. install
  2. Docker image build with PHP zip extension shows “bundled libzip is deprecated” warning