0

我想在后台启动一个 php 脚本。我正在做的是运行这段代码

<?php
while(true){
$commandString = 'start /b C:\xampp\php\php.exe  "C:\xampp\htdocs\caliban\blobs.php"'; 
popen($commandString, 'r'); 
sleep(5);
}
?>

在网络浏览器中,但页面不会停止加载。如何执行此代码并停止网络浏览器进一步加载而不停止在后台完成的任务?

斑点.php

<?php

//pdo connect function
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}

//third function
$firstname = rand(4,4);
$lastname = rand(4,4);
$city = rand(4,4);
$continent = rand(4,4);
$profile = rand(4,4);
$image = rand(4,4);
$sql = "INSERT INTO mymodels ".
       "(firstname,lastname,city,continent,image,profile) ".
       "VALUES ".
       "('$firstname','$lastname','$city','$continent','$image','$profile')";
mysql_select_db('caliban');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not enter data: ' . mysql_error());
}



?>

Sql

create table mymodels(
   id INT NOT NULL AUTO_INCREMENT,
   firstname VARCHAR(100) NOT NULL,
   lastname VARCHAR(40) NOT NULL,
   city VARCHAR(40) NOT NULL,
   continent VARCHAR(40) NOT NULL,
   image BLOB,
   profile VARCHAR(400) NOT NULL,
   PRIMARY KEY ( id )
);
4

2 回答 2

1
function close_connection(){
    ob_end_clean();
    header("Connection: close");
    ignore_user_abort(); // optional
    ob_start();
    $size = ob_get_length();
    header("Content-Length: $size");
    ob_end_flush();
    flush();
}

然后

<?php
    close_connection();
    while(true){
        $commandString = 'start /b C:\xampp\php\php.exe  "C:\xampp\htdocs\caliban\blobs.php"'; 
        popen($commandString, 'r'); 
        sleep(5);
    }
?>
于 2013-06-10T08:01:11.927 回答
0

这样做

<?php
function close_connection(){
    ob_end_clean();
    header("Connection: close");
    ignore_user_abort(); // optional
    ob_start();
    $size = ob_get_length();
    header("Content-Length: $size");
    ob_end_flush();
    flush();
}
close_connection();
exec('c:\WINDOWS\system32\cmd.exe /c START C:\xampp\htdocs\caliban\blobs.bat');

?>

工作。这是我的 blobs.bat

php c:\xampp\htdocs\caliban\blob.php

完全隐藏命令行

我创建了这个 in.vbs 文件并将其放入

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

我的 php 文件看起来像

<?php
function close_connection(){
    ob_end_clean();
    header("Connection: close");
    ignore_user_abort(); // optional
    ob_start();
    $size = ob_get_length();
    header("Content-Length: $size");
    ob_end_flush();
    flush();
}
close_connection();
exec('c:\WINDOWS\system32\cmd.exe /c START C:\xampp\htdocs\caliban\in.vbs C:\xampp\htdocs\caliban\blobs.bat');

?>

希望这对其他人有帮助。

参考

https://superuser.com/questions/62525/run-a-completly-hidden-batch-file

于 2013-06-10T09:31:00.720 回答