我正在尝试编写一个执行SQL备份的php程序,并且我有太多的数据库,我想将进程分成3个单独的进程。
我的备份.php文件接受一个字符串参数,并输出文本数据以显示备份进度。
所以这是我试图实现的逻辑。
while(there is still items in the list){
open backup.php?s=listx
x++
}
//continue with loop and open more processes
有没有办法在新选项卡中打开这些页面? 我尝试使用 curl,但这似乎不起作用,我想我已经在某处读到 html 标签或 javascript 代码无法在 php 代码中运行?
感谢您的帮助,如果我的描述含糊不清,请告诉我并尝试扩展它。这是我的主备份代码.php
<?php
// Doesnt open a new page for me..
function callpage($url)
{
$ch = curl_init();
$timeout = 1;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
curl_close($ch);
}
$link = mysql_connect('host', 'user', 'password');
//set each process to handle 60 databases
$limit=60;
$count=0;
$s="";
while ($row = mysql_fetch_assoc($link)) {
//echo $row['Database'] . "'n";
if($count <$limit)
{
$count++;
$s.= $row['dbs']. ",";
}
else
{
//exec('php backup.php s='$s);
$l='localhost/backup/backup.php?s=';
$l.=$s;
//window.open($l);
callpage($l);
//substr_replace($s ,"",-1);
//echo "'n'n'n'n'n'n'n'n'n";
$count=0;
$s="";
}
}
?>
以为我会在这里发布我的解决方案,以防其他人在看。使用 php 输出可以打开选项卡的 JavaScript。写得很快,所以它也打开了同一页面并出现错误。我想你可以稍后解决这个问题。
<?php
echo "<html><body>";
$link = mysql_connect('remotehost', 'user', 'password');
$res = mysql_query("selective databases");
$limit=80;
$count=0;
$s="";
$link = '<a href="javascript:open_wins()">start backup</a><script>function open_wins(){window.open("backup.php?s=';
while ($row = mysql_fetch_assoc($res)) {
if($count <$limit)
{
$count++;
$s.= $row['dbs']. ",";
}
else
{
$link.=$s;
$link.='");window.open("backup.php?s=';
$count=0;
$s="";
}
}
$link.='");window.close();}</script></html>';
echo $link;
echo "</html></body>";
?>
您可以
让备份过程为它将输出到这些页面的每个单独数据集(所需的选项卡)创建一个新页面,然后在原始页面上显示指向包含信息的页面的链接(HTML 在新选项卡中打开)。