4月 24, 2023 - php开发    exec执行scp输入密码的交互命令已关闭评论

exec执行scp输入密码的交互命令

将一个文件用nginx用户的scp的方式,拷贝到另一台服务器上并使用root用户链接,如果是首次链接则可能会要求输入yes/no,和密码,则可以:

//将.env拷贝到新创建的服务器上,密码链接超时时间为300s,有提示输入yes/no则自动输入yes
$scp = "expect -c 'spawn scp /var/www/html/staging/mpace-stage.ividxx.cn/.env root@182.4.2.23:/var/www/html/staging/mpxxx.ivideocloud.cn/
    expect {
    \"*assword\"[......]

Read more

4月 11, 2023 - laravel    Laravel使用orm的chunk且有delete时删除不全已关闭评论

Laravel使用orm的chunk且有delete时删除不全

Laravel使用orm的chunk且有delete时会遇到删除不全的问题:

Image::where('property_id', 48)->chunk(2, function ($images) {

    foreach ($images as $image) {

        $image->delete();

    }

});

假如有5条数据,则运行后期望是全部删除,但实际会剩余2条数据.

应该使用chunkById这种方式:

Image::where('property_id', 48)->chunkById(2, fu[......]

Read more

3月 20, 2023 - laravel    Laravel6 export customize data to excel file.已关闭评论

Laravel6 export customize data to excel file.

使用composer包工具:maatwebsite/excel

"maatwebsite/excel": "^3.1

步骤:

1:先定义一个export的Object

<?php

namespace App\Imports;

use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Imports\HeadingRowFormatter;

HeadingRowFormatter::default('none');

class UsersImport implements FromA[......]

Read more

页面:«1...10111213141516...44»