gpt4 book ai didi

php - 在 php 中调用 exec()

转载 作者:太空宇宙 更新时间:2023-11-04 12:10:30 24 4
gpt4 key购买 nike

刚刚将网站从没有 cpanel 的 linux 服务器迁移到有 cpanel 的服务器。我的问题是当我点击开始启动一个执行 php 文件的进程时。它不会运行该文件。如果我从终端运行文件,一切正常。

调用文件的代码。

if ($do === "start_service") {
create_marker_file("$service_running_marker");
system_bg("php $dir/$service_script");
$message = "Started Service!";
$running = true;
$status = "Running";
}

systembg 是一个函数。

function system_bg($command) {
exec('bash -c "exec nohup setsid ' . $command . ' > /dev/null 2>&1 &"');
}

如果我做 ps ax | grep service.php 在终端中看到这个

/opt/cpanel/ea-php70/root/usr/bin/php-cgi /home/xsocial1/public_html/xsmp/service.php

当我在终端中运行文件时,这是我运行 ps ax | 时看到的内容grep 服务.php

/opt/cpanel/ea-php70/root/usr/bin/php service.php

我认为我的问题是我需要服务器调用 cli 调用而不是 cgi 调用

最佳答案

这是正确的,您需要找出 CLI PHP 路径并使用它来启动该过程。遗憾的是,这并没有完全标准化,但是在 *nix 机器上,您通常可以通过使用 PHP_BINDIR .'/php'(PHP_BINDIR 是一个 PHP 常量)来获得正确的标准。

关于php - 在 php 中调用 exec(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49159056/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com