Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用Swoole\Process::exec()报错:PHP Warning: sr/bin/php) failed, Error: Argument list too long[7] #5195

Closed
wangsijia opened this issue Nov 20, 2023 · 2 comments
Labels

Comments

@wangsijia
Copy link

wangsijia commented Nov 20, 2023

Please answer these questions before submitting your issue.

  1. What did you do? If possible, provide a simple script for reproducing the error.
$workerNum = 2;//线程数

$pool      = new Swoole\Process\Pool($workerNum);

$pool->on("WorkerStart", function ($pool, $workerId) use ($database, $params, $logger,$workerNum) {
    try {
    $mysqli = new Mysqli($database['host'], $database['username'], $database['password'], $database['dbname']);
    $table  = 'excel_task';
    $rest_service = new ResetService();
    while (true) {

            //利用swoole线程池
            $sql = "
                select user_id,
                   executable_path,
                   action_name,
                   args_json,
                   id
              from `excel_task`
             where flag= 0
               and action_name is not null
               and mod(id,$workerNum)=$workerId
               and `executable_path` IS NULL 
             ORDER BY `id` asc;
                ";
            $result = $mysqli->query($sql);
            $res    = $result->fetch_row();

            if ($res) {
                $v           = $res;
                $process     = $pool->getProcess();
                $executable  = $v[1] ?? $params['config']['application']['appDir'] . 'cli.php';
                $action      = explode(',', $v[2]);
                $task_name   = $action[0];
                $action_name = $action[1];
                $arg1        = $v[3];
                $arg2        = $v[4];
                if (empty($action_name)){
                    $args = [$executable, $task_name, $arg1,$arg2];
                    $process->exec(PHP_BINDIR . '/php', $args); // exec 系统调用
                }else{
                    $args = [$executable, $task_name, $action_name, $arg1,$arg2];
                    $process->exec(PHP_BINDIR . '/php', $args); // exec 系统调用
                    

                }

            } else {
                sleep(1);

            }

    }
    } catch (\Exception $e) {
        $logger->write_log("=================begin hubbonusAction " . time() . "==========", 'info');
        exit;
    }
});
$pool->start();
$logger->write_log("=================begin hubbonusAction " . time() . "==========", 'info');
  1. What did you expect to see?
    $process->exec() 正常调起新进程

  2. What did you see instead?
    PHP Warning:
    Swoole Process::exec(): execv(/usr/bin/php) failed, Error: Argument list too long[7]

  3. What version of Swoole are you using (show your php --ri swoole)?
    swoole

Swoole => enabled
Author => Swoole Team team@swoole.com
Version => 4.7.1
Built => Aug 26 2021 21:33:45
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
pcre => enabled
zlib => 1.2.11
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608

  1. What is your machine environment used (show your uname -a & php -v & gcc -v) ?
    uname -a
    Linux my-alimy-ard-bi-pro-5-186 4.15.0-144-generic fixbug of swTaskWorker_finish #148-Ubuntu SMP Sat May 8 02:33:43 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

php -v
PHP 7.2.34-23+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Jul 1 2021 16:06:47) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.34-23+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.5.0-3ubuntu118.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1
18.04)

@matyhtf
Copy link
Member

matyhtf commented Nov 21, 2023

命令参数无法传递太长的内容,建议使用标准输入输出与进程交互,而不是将所有内容都放到 argv 中。

@wangsijia
Copy link
Author

命令参数无法传递太长的内容,建议使用标准输入输出与进程交互,而不是将所有内容都放到 argv 中。

您说的这个怎么实现呢?能举个简单的例子吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants