0

別のphpスクリプトからバックグラウンドphpスクリプトを開始するために、多数の方法を試しました。ダウンロード用のデータベース ファイルの zip ファイルを作成する必要があります。単一のファイルを即座にダウンロードするように設定していますが、ファイルを圧縮する必要がある場合は、zip ファイルへのリンクを電子メールで送信するバックグラウンド プロセスを開始したいと考えています。プロセスは機能しますが、元のスクリプトはプロセスが完了するまで待機します。私は次の方法を試しましたが、私が言ったように、それらは機能しますが、バックグラウンドにはなりません。特定のインスタンス (大きなファイルの zip) で 8 分以上待たされましたが、それを待つユーザーはいません。

print `php -f zipfiles7.php | at now`;

$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run("C:\wamp\bin\php\php5.4.3\php.exe -f C:/wamp/www/zipfiles7.php", 0, false);

$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run("cmd /c C:\wamp\bin\php\php5.4.3\php.exe -f C:/wamp/www/zipfiles7.php", 3, false);

$exe = "C:\wamp\bin\php\php5.4.3\php.exe";
$args = "C:\wamp\www\zipfiles7.php";
pclose(popen("start \"bla\" \"" . $exe . "\" " . escapeshellarg($args), "r"));

$cmd = "php-win.exe zipfiles7.php";
$cmd = "start /B php-win.exe zipfiles7.php";
$PID = shell_exec("nohup $cmd > test.txt 2>&1");

exec("Psexec.exe -i -d  php.exe zipfiles7.php");

$cmd = "C:\wamp\bin\php\php5.4.3\php-win.exe -f C:\wamp\www\zipfiles7.php";
function _exec($cmd)
{
    $WshShell = new COM("WScript.Shell");
    $oExec = $WshShell->Run($cmd, 0,false);
    echo $cmd;
    return $oExec == 0 ? true : false;
}_exec("C:\wamp\bin\php\php5.4.3\php-win.exe -f C:\wamp\www\zipfiles7.php");

$cmd = "C:\wamp\bin\php\php5.4.3\php-win.exe -f C:\wamp\www\zipfiles7.php";
pclose(popen('start /B ' . $cmd, 'r'));

$cmd = "C:\wamp\bin\php\php5.4.3\php-win.exe -f C:\wamp\www\zipfiles7.php";
pclose(popen("start /B " . $cmd, "r"));

system("cmd /c php zipfiles7.php > test.txt 2>&1");

exec('psexec start /B -d php.exe zipfiles7.php > test.txt 2>&1');

exec('psexec -d php.exe zipfiles7.php > test.txt 2>&1');

exec('psexec -d php.exe zipfiles7.php');

$cmd = "C:\wamp\bin\php\php5.4.3\php-win.exe -f C:\wamp\www\zipfiles7.php";
exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, "test.txt", "php_error.log"));

pclose(popen('start /B php zipfiles7.php > test.txt 2>&1', 'r'));

pclose(popen("start /B C:\wamp\bin\php\php5.4.3\php-win.exe -f C:\wamp\www\zipfiles7.php", "r"));

shell_exec('start /B "C:\wamp\bin\php\php5.4.3\php.exe -f C:\wamp\www\zipfiles7.php > test.txt 2>&1"');

exec('START /B "C:\wamp\bin\php\php5.4.3\php.exe -f C:\wamp\www\zipfiles7.php"', $output);

passthru("start /B c:/wamp/bin/php/php5.4.3/php-win c:/wamp/www/zipfiles7.php > test.txt 2>&1");

exec("php.exe -f zipfiles7.php > test.txt 2>&1");

exec("php-win -f zipfiles7.php > /dell/null 2>/dev/null &", $output);

exec("start /B php zipfiles7.php > test.txt 2>&1");

exec("start php.exe -f zipfiles7.php > test.txt 2>&1");

$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run("cmd /C C:\wamp\www\batch.bat", 0, false);

exec("CHP.exe C:\wamp\www\batch.bat > test.txt 2>&1");

exec("start /min php zipfiles7.php > test.txt 2>&1");

shell_exec('call "cmd /c batch.bat"'); 

バッチ.バット

@echo off 
"start /B bg C:\wamp\bin\php\php5.4.3\php.exe -f C:\wamp\www\zipfiles7.php > test.txt"

試した追加の方法:

$descriptorspec = array(
        0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
        1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
        2 => array("pipe", "r") // stderr is a file to write to
    );

    $cmd = "start /B php.exe zipfiles7.php";
    $process = proc_open($cmd, $descriptorspec, $pipes, null, null);
    if (is_resource($process))
    { ....

// buffer all upcoming output
ob_start();
// get the size of the output
$size = ob_get_length();

// send headers to tell the browser to close the connection
header("Content-Length: $size");
header('Connection: close');

// flush all output
ob_end_flush();
ob_flush();
flush();

// close current session
if (session_id()) session_write_close();
    exec("start /B php zipfiles7.php > test.txt 2>&1");

また

shell_exec('psexec -s -d php.exe zipfiles7.php');

また

$runCommand = 'php -q zipfiles7.php';
    $WshShell = new COM(“WScript.Shell”);
    $oExec = $WshShell->Run($runCommand, 7, false);

JavaScriptを試してみても

function background(){
var url = "C:\wamp\www\zipfiles7.php";// No question mark needed

xmlReq=new XMLHttpRequest();

xmlReq.open("POST",url,true);
xmlReq.send();
console.log("done");
}
echo '<script type="text/javascript">', 'background();', '</script>';

また

function background(){
var str = "Success";
var url = "C:\wamp\www\zipfiles7.php";

xmlReq=new XMLHttpRequest();

xmlReq.open("POST",url,true);
xmlReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlReq.setRequestHeader("Content-length", str.length);
xmlReq.setRequestHeader("Connection", "close");
xmlReq.send();
console.log("done");
}

Ajax でさえバックグラウンドにはなりません。

function background()
{
$.ajax(
    {
           type: "POST",
           url: "zipfiles7.php",
           data: data, // data to send to above script page if any
           cache: false,

           success: function(response)
           {
                alert('Succes');
           }
     });
}

プロセスがバックグラウンドに移行しない理由を理解してください。前もって感謝します。

4

1 に答える 1