Php 如何按常规小部分更新数据库表 SD->流行度['TEXT']; }
我有这个脚本,我使用wordpress数据库类而不使用wordpress。我将行数限制为200行,因为否则我会遇到一些问题,比如页面加载需要几年时间,或者来自alexa函数的xml需要很长的php执行时间。我有很多URL要在数据库中检查,我想用一个操作更新它们,这意味着取消200个限制。我需要做什么才能让它像一次做50个,然后输出,然后继续?AJAX我该怎么做Php 如何按常规小部分更新数据库表 SD->流行度['TEXT']; },php,mysql,ajax,loops,foreach,Php,Mysql,Ajax,Loops,Foreach,我有这个脚本,我使用wordpress数据库类而不使用wordpress。我将行数限制为200行,因为否则我会遇到一些问题,比如页面加载需要几年时间,或者来自alexa函数的xml需要很长的php执行时间。我有很多URL要在数据库中检查,我想用一个操作更新它们,这意味着取消200个限制。我需要做什么才能让它像一次做50个,然后输出,然后继续?AJAX我该怎么做 $page = $_GET["page"]; // I skip the validation, you should do it be
$page = $_GET["page"]; // I skip the validation, you should do it be yourself
require_once( dirname(__FILE__) . '/shared.php');
function tabelle_holen_hosters( $condition = "" ) {
global $wpdb;
$sql = "SELECT * FROM whatever" . $condition;
if( $table = $wpdb->get_results( $sql, ARRAY_A ) ) {
return $table;
} else {
echo "SQL ERROR in tabelle_holen()";
var_dump( $table );
return false;
}
}
function alexaRank( $url ) {
$request_url = "http://data.alexa.com/data?cli=10&url=".$url;
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml->SD->POPULARITY['TEXT'];
}
$limit = 200;
$start= $page*$limit;
$test = tabelle_holen_hosters( " WHERE working=1 AND alexacheck=0 LIMIT $start,$limit" );
$str = '<table>';
foreach ( $test as $row ){
$rank = (int) alexaRank( $row['hoster'] );
if ($rank == 0)
$rank = 999999999;
$str.= '<tr>';
$str.= '<td>' . $row['hoster_id'] . '</td>';
$str.= '<td>' . $row['hoster'] . '</td>';
$str.= '<td>' . $rank . '<td>';
$str.= '</tr>';
$wpdb->update(
'fhw_filehosters',
array(
'alexa' => $rank,
'alexacheck' => 1
),
array( 'hoster_id' => $row['hoster_id'] ),
array(
'%d',
'%d'
),
array( '%d' )
);
}
$str.='</table>';
echo $str;
exit;
?>
更新1:
$page = $_GET["page"]; // I skip the validation, you should do it be yourself
require_once( dirname(__FILE__) . '/shared.php');
function tabelle_holen_hosters( $condition = "" ) {
global $wpdb;
$sql = "SELECT * FROM whatever" . $condition;
if( $table = $wpdb->get_results( $sql, ARRAY_A ) ) {
return $table;
} else {
echo "SQL ERROR in tabelle_holen()";
var_dump( $table );
return false;
}
}
function alexaRank( $url ) {
$request_url = "http://data.alexa.com/data?cli=10&url=".$url;
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml->SD->POPULARITY['TEXT'];
}
$limit = 200;
$start= $page*$limit;
$test = tabelle_holen_hosters( " WHERE working=1 AND alexacheck=0 LIMIT $start,$limit" );
$str = '<table>';
foreach ( $test as $row ){
$rank = (int) alexaRank( $row['hoster'] );
if ($rank == 0)
$rank = 999999999;
$str.= '<tr>';
$str.= '<td>' . $row['hoster_id'] . '</td>';
$str.= '<td>' . $row['hoster'] . '</td>';
$str.= '<td>' . $rank . '<td>';
$str.= '</tr>';
$wpdb->update(
'fhw_filehosters',
array(
'alexa' => $rank,
'alexacheck' => 1
),
array( 'hoster_id' => $row['hoster_id'] ),
array(
'%d',
'%d'
),
array( '%d' )
);
}
$str.='</table>';
echo $str;
exit;
?>
正如我在评论中所说,我正在寻找一些东西来实现我的网站(在后台)的这种情况,实际上我并不确定这一点是否达到了php执行时间限制,但对于“一次性”解决方案,我只是在队列末尾测试了flush(),它不起作用
$page = $_GET["page"]; // I skip the validation, you should do it be yourself
require_once( dirname(__FILE__) . '/shared.php');
function tabelle_holen_hosters( $condition = "" ) {
global $wpdb;
$sql = "SELECT * FROM whatever" . $condition;
if( $table = $wpdb->get_results( $sql, ARRAY_A ) ) {
return $table;
} else {
echo "SQL ERROR in tabelle_holen()";
var_dump( $table );
return false;
}
}
function alexaRank( $url ) {
$request_url = "http://data.alexa.com/data?cli=10&url=".$url;
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml->SD->POPULARITY['TEXT'];
}
$limit = 200;
$start= $page*$limit;
$test = tabelle_holen_hosters( " WHERE working=1 AND alexacheck=0 LIMIT $start,$limit" );
$str = '<table>';
foreach ( $test as $row ){
$rank = (int) alexaRank( $row['hoster'] );
if ($rank == 0)
$rank = 999999999;
$str.= '<tr>';
$str.= '<td>' . $row['hoster_id'] . '</td>';
$str.= '<td>' . $row['hoster'] . '</td>';
$str.= '<td>' . $rank . '<td>';
$str.= '</tr>';
$wpdb->update(
'fhw_filehosters',
array(
'alexa' => $rank,
'alexacheck' => 1
),
array( 'hoster_id' => $row['hoster_id'] ),
array(
'%d',
'%d'
),
array( '%d' )
);
}
$str.='</table>';
echo $str;
exit;
?>
但我正在寻找一个常规的功能,现在我更新了问题,答案是非常一般的,我不是经验。我想看到一些实际的代码。如果这太多了,而且倾向于“给我写一个程序”,那么我必须花些时间挖掘,找出这个问题。然后我将接受最有帮助的答案。您的直接问题(脚本运行时如何启动输出)很容易回答:
<?php
require_once( dirname(__FILE__) . '/shared.php');
function tabelle_holen_hosters( $condition = "" ) {
global $wpdb;
$sql = "SELECT * FROM whatever" . $condition;
if( $table = $wpdb->get_results( $sql, ARRAY_A ) ) {
return $table;
} else {
echo "SQL ERROR in tabelle_holen()";
var_dump( $table );
return false;
}
}
$test = tabelle_holen_hosters( " WHERE working=1 AND alexacheck=0 LIMIT 200" );
?>
<table>
<tbody>
<?php
foreach ( $test as $row ){
$rank = (int) alexaRank( $row['hoster'] );
if ($rank == 0)
$rank = 999999999;
echo '<tr>';
echo '<td>' . $row['hoster_id'] . '</td>';
echo '<td>' . $row['hoster'] . '</td>';
echo '<td>' . $rank . '<td>';
echo '</tr>';
$wpdb->update(
'fhw_filehosters',
array(
'alexa' => $rank,
'alexacheck' => 1
),
array( 'hoster_id' => $row['hoster_id'] ),
array(
'%d',
'%d'
),
array( '%d' )
);
flush(); // <----- NOT working.
}
?>
</tbody>
</table>
<?php
function alexaRank( $url ) {
$request_url = "http://data.alexa.com/data?cli=10&url=".$url;
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml->SD->POPULARITY['TEXT'];
}
$page = $_GET["page"]; // I skip the validation, you should do it be yourself
require_once( dirname(__FILE__) . '/shared.php');
function tabelle_holen_hosters( $condition = "" ) {
global $wpdb;
$sql = "SELECT * FROM whatever" . $condition;
if( $table = $wpdb->get_results( $sql, ARRAY_A ) ) {
return $table;
} else {
echo "SQL ERROR in tabelle_holen()";
var_dump( $table );
return false;
}
}
function alexaRank( $url ) {
$request_url = "http://data.alexa.com/data?cli=10&url=".$url;
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml->SD->POPULARITY['TEXT'];
}
$limit = 200;
$start= $page*$limit;
$test = tabelle_holen_hosters( " WHERE working=1 AND alexacheck=0 LIMIT $start,$limit" );
$str = '<table>';
foreach ( $test as $row ){
$rank = (int) alexaRank( $row['hoster'] );
if ($rank == 0)
$rank = 999999999;
$str.= '<tr>';
$str.= '<td>' . $row['hoster_id'] . '</td>';
$str.= '<td>' . $row['hoster'] . '</td>';
$str.= '<td>' . $rank . '<td>';
$str.= '</tr>';
$wpdb->update(
'fhw_filehosters',
array(
'alexa' => $rank,
'alexacheck' => 1
),
array( 'hoster_id' => $row['hoster_id'] ),
array(
'%d',
'%d'
),
array( '%d' )
);
}
$str.='</table>';
echo $str;
exit;
?>
但如果PHP执行时间限制限制了您,那么它将无法解决您的问题。这就剩下AJAX了:
$page = $_GET["page"]; // I skip the validation, you should do it be yourself
require_once( dirname(__FILE__) . '/shared.php');
function tabelle_holen_hosters( $condition = "" ) {
global $wpdb;
$sql = "SELECT * FROM whatever" . $condition;
if( $table = $wpdb->get_results( $sql, ARRAY_A ) ) {
return $table;
} else {
echo "SQL ERROR in tabelle_holen()";
var_dump( $table );
return false;
}
}
function alexaRank( $url ) {
$request_url = "http://data.alexa.com/data?cli=10&url=".$url;
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml->SD->POPULARITY['TEXT'];
}
$limit = 200;
$start= $page*$limit;
$test = tabelle_holen_hosters( " WHERE working=1 AND alexacheck=0 LIMIT $start,$limit" );
$str = '<table>';
foreach ( $test as $row ){
$rank = (int) alexaRank( $row['hoster'] );
if ($rank == 0)
$rank = 999999999;
$str.= '<tr>';
$str.= '<td>' . $row['hoster_id'] . '</td>';
$str.= '<td>' . $row['hoster'] . '</td>';
$str.= '<td>' . $rank . '<td>';
$str.= '</tr>';
$wpdb->update(
'fhw_filehosters',
array(
'alexa' => $rank,
'alexacheck' => 1
),
array( 'hoster_id' => $row['hoster_id'] ),
array(
'%d',
'%d'
),
array( '%d' )
);
}
$str.='</table>';
echo $str;
exit;
?>
- 将脚本分为两个文件:一个包含空的
和JavaScript,另一个将通过AJAX调用,执行实际处理并返回表行 - 限制处理的行数,如下所示:
,其中limit$start,50
通过GET/POST参数提供$start
- 在JavaScript中,首先调用start=0的PHP脚本,然后在处理响应后,再次调用start增加50的PHP脚本。重复,直到响应为空
你想进行批量更新吗?看看这个。或者你也可以使用。如果在工作和检查中有很多不同的状态,不要忘记索引它们 以下是您应该如何看待它:
$page = $_GET["page"]; // I skip the validation, you should do it be yourself
require_once( dirname(__FILE__) . '/shared.php');
function tabelle_holen_hosters( $condition = "" ) {
global $wpdb;
$sql = "SELECT * FROM whatever" . $condition;
if( $table = $wpdb->get_results( $sql, ARRAY_A ) ) {
return $table;
} else {
echo "SQL ERROR in tabelle_holen()";
var_dump( $table );
return false;
}
}
function alexaRank( $url ) {
$request_url = "http://data.alexa.com/data?cli=10&url=".$url;
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml->SD->POPULARITY['TEXT'];
}
$limit = 200;
$start= $page*$limit;
$test = tabelle_holen_hosters( " WHERE working=1 AND alexacheck=0 LIMIT $start,$limit" );
$str = '<table>';
foreach ( $test as $row ){
$rank = (int) alexaRank( $row['hoster'] );
if ($rank == 0)
$rank = 999999999;
$str.= '<tr>';
$str.= '<td>' . $row['hoster_id'] . '</td>';
$str.= '<td>' . $row['hoster'] . '</td>';
$str.= '<td>' . $rank . '<td>';
$str.= '</tr>';
$wpdb->update(
'fhw_filehosters',
array(
'alexa' => $rank,
'alexacheck' => 1
),
array( 'hoster_id' => $row['hoster_id'] ),
array(
'%d',
'%d'
),
array( '%d' )
);
}
$str.='</table>';
echo $str;
exit;
?>
- 创建一个大的上帝之母循环
- 保留$total计数器和$temp计数器
- 循环迭代100(n)次,每次增加计数器
- 一旦您达到100个数字限制(或50或200或其他),您将重置温度计数器
- 你让程序进入睡眠状态3秒钟(或类似的时间)
- 您再次遍历temp变量n次,但请求与$total计数器对应的数据
$page = $_GET["page"]; // I skip the validation, you should do it be yourself
require_once( dirname(__FILE__) . '/shared.php');
function tabelle_holen_hosters( $condition = "" ) {
global $wpdb;
$sql = "SELECT * FROM whatever" . $condition;
if( $table = $wpdb->get_results( $sql, ARRAY_A ) ) {
return $table;
} else {
echo "SQL ERROR in tabelle_holen()";
var_dump( $table );
return false;
}
}
function alexaRank( $url ) {
$request_url = "http://data.alexa.com/data?cli=10&url=".$url;
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml->SD->POPULARITY['TEXT'];
}
$limit = 200;
$start= $page*$limit;
$test = tabelle_holen_hosters( " WHERE working=1 AND alexacheck=0 LIMIT $start,$limit" );
$str = '<table>';
foreach ( $test as $row ){
$rank = (int) alexaRank( $row['hoster'] );
if ($rank == 0)
$rank = 999999999;
$str.= '<tr>';
$str.= '<td>' . $row['hoster_id'] . '</td>';
$str.= '<td>' . $row['hoster'] . '</td>';
$str.= '<td>' . $rank . '<td>';
$str.= '</tr>';
$wpdb->update(
'fhw_filehosters',
array(
'alexa' => $rank,
'alexacheck' => 1
),
array( 'hoster_id' => $row['hoster_id'] ),
array(
'%d',
'%d'
),
array( '%d' )
);
}
$str.='</table>';
echo $str;
exit;
?>
- 创建一个大的上帝之母循环
- 有一个柜台
- 在每次循环迭代中增加计数器
- 一旦反击达到你定义的最大值,你就重置它
- 睡觉
- 重复一遍
$page = $_GET["page"]; // I skip the validation, you should do it be yourself
require_once( dirname(__FILE__) . '/shared.php');
function tabelle_holen_hosters( $condition = "" ) {
global $wpdb;
$sql = "SELECT * FROM whatever" . $condition;
if( $table = $wpdb->get_results( $sql, ARRAY_A ) ) {
return $table;
} else {
echo "SQL ERROR in tabelle_holen()";
var_dump( $table );
return false;
}
}
function alexaRank( $url ) {
$request_url = "http://data.alexa.com/data?cli=10&url=".$url;
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml->SD->POPULARITY['TEXT'];
}
$limit = 200;
$start= $page*$limit;
$test = tabelle_holen_hosters( " WHERE working=1 AND alexacheck=0 LIMIT $start,$limit" );
$str = '<table>';
foreach ( $test as $row ){
$rank = (int) alexaRank( $row['hoster'] );
if ($rank == 0)
$rank = 999999999;
$str.= '<tr>';
$str.= '<td>' . $row['hoster_id'] . '</td>';
$str.= '<td>' . $row['hoster'] . '</td>';
$str.= '<td>' . $rank . '<td>';
$str.= '</tr>';
$wpdb->update(
'fhw_filehosters',
array(
'alexa' => $rank,
'alexacheck' => 1
),
array( 'hoster_id' => $row['hoster_id'] ),
array(
'%d',
'%d'
),
array( '%d' )
);
}
$str.='</table>';
echo $str;
exit;
?>
现在,由于您需要一些代码和解释:
$page = $_GET["page"]; // I skip the validation, you should do it be yourself
require_once( dirname(__FILE__) . '/shared.php');
function tabelle_holen_hosters( $condition = "" ) {
global $wpdb;
$sql = "SELECT * FROM whatever" . $condition;
if( $table = $wpdb->get_results( $sql, ARRAY_A ) ) {
return $table;
} else {
echo "SQL ERROR in tabelle_holen()";
var_dump( $table );
return false;
}
}
function alexaRank( $url ) {
$request_url = "http://data.alexa.com/data?cli=10&url=".$url;
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml->SD->POPULARITY['TEXT'];
}
$limit = 200;
$start= $page*$limit;
$test = tabelle_holen_hosters( " WHERE working=1 AND alexacheck=0 LIMIT $start,$limit" );
$str = '<table>';
foreach ( $test as $row ){
$rank = (int) alexaRank( $row['hoster'] );
if ($rank == 0)
$rank = 999999999;
$str.= '<tr>';
$str.= '<td>' . $row['hoster_id'] . '</td>';
$str.= '<td>' . $row['hoster'] . '</td>';
$str.= '<td>' . $rank . '<td>';
$str.= '</tr>';
$wpdb->update(
'fhw_filehosters',
array(
'alexa' => $rank,
'alexacheck' => 1
),
array( 'hoster_id' => $row['hoster_id'] ),
array(
'%d',
'%d'
),
array( '%d' )
);
}
$str.='</table>';
echo $str;
exit;
?>
PHP手册说明:
flush();
$page = $_GET["page"]; // I skip the validation, you should do it be yourself
require_once( dirname(__FILE__) . '/shared.php');
function tabelle_holen_hosters( $condition = "" ) {
global $wpdb;
$sql = "SELECT * FROM whatever" . $condition;
if( $table = $wpdb->get_results( $sql, ARRAY_A ) ) {
return $table;
} else {
echo "SQL ERROR in tabelle_holen()";
var_dump( $table );
return false;
}
}
function alexaRank( $url ) {
$request_url = "http://data.alexa.com/data?cli=10&url=".$url;
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml->SD->POPULARITY['TEXT'];
}
$limit = 200;
$start= $page*$limit;
$test = tabelle_holen_hosters( " WHERE working=1 AND alexacheck=0 LIMIT $start,$limit" );
$str = '<table>';
foreach ( $test as $row ){
$rank = (int) alexaRank( $row['hoster'] );
if ($rank == 0)
$rank = 999999999;
$str.= '<tr>';
$str.= '<td>' . $row['hoster_id'] . '</td>';
$str.= '<td>' . $row['hoster'] . '</td>';
$str.= '<td>' . $rank . '<td>';
$str.= '</tr>';
$wpdb->update(
'fhw_filehosters',
array(
'alexa' => $rank,
'alexacheck' => 1
),
array( 'hoster_id' => $row['hoster_id'] ),
array(
'%d',
'%d'
),
array( '%d' )
);
}
$str.='</table>';
echo $str;
exit;
?>
因此,程序执行被延迟,如果延迟了执行时间,则无法达到限制
$page = $_GET["page"]; // I skip the validation, you should do it be yourself
require_once( dirname(__FILE__) . '/shared.php');
function tabelle_holen_hosters( $condition = "" ) {
global $wpdb;
$sql = "SELECT * FROM whatever" . $condition;
if( $table = $wpdb->get_results( $sql, ARRAY_A ) ) {
return $table;
} else {
echo "SQL ERROR in tabelle_holen()";
var_dump( $table );
return false;
}
}
function alexaRank( $url ) {
$request_url = "http://data.alexa.com/data?cli=10&url=".$url;
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml->SD->POPULARITY['TEXT'];
}
$limit = 200;
$start= $page*$limit;
$test = tabelle_holen_hosters( " WHERE working=1 AND alexacheck=0 LIMIT $start,$limit" );
$str = '<table>';
foreach ( $test as $row ){
$rank = (int) alexaRank( $row['hoster'] );
if ($rank == 0)
$rank = 999999999;
$str.= '<tr>';
$str.= '<td>' . $row['hoster_id'] . '</td>';
$str.= '<td>' . $row['hoster'] . '</td>';
$str.= '<td>' . $rank . '<td>';
$str.= '</tr>';
$wpdb->update(
'fhw_filehosters',
array(
'alexa' => $rank,
'alexacheck' => 1
),
array( 'hoster_id' => $row['hoster_id'] ),
array(
'%d',
'%d'
),
array( '%d' )
);
}
$str.='</table>';
echo $str;
exit;
?>
所以你可以这样做:
int sleep ( int $seconds )
"Delays the program execution for the given number of seconds."
$page = $_GET["page"]; // I skip the validation, you should do it be yourself
require_once( dirname(__FILE__) . '/shared.php');
function tabelle_holen_hosters( $condition = "" ) {
global $wpdb;
$sql = "SELECT * FROM whatever" . $condition;
if( $table = $wpdb->get_results( $sql, ARRAY_A ) ) {
return $table;
} else {
echo "SQL ERROR in tabelle_holen()";
var_dump( $table );
return false;
}
}
function alexaRank( $url ) {
$request_url = "http://data.alexa.com/data?cli=10&url=".$url;
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml->SD->POPULARITY['TEXT'];
}
$limit = 200;
$start= $page*$limit;
$test = tabelle_holen_hosters( " WHERE working=1 AND alexacheck=0 LIMIT $start,$limit" );
$str = '<table>';
foreach ( $test as $row ){
$rank = (int) alexaRank( $row['hoster'] );
if ($rank == 0)
$rank = 999999999;
$str.= '<tr>';
$str.= '<td>' . $row['hoster_id'] . '</td>';
$str.= '<td>' . $row['hoster'] . '</td>';
$str.= '<td>' . $rank . '<td>';
$str.= '</tr>';
$wpdb->update(
'fhw_filehosters',
array(
'alexa' => $rank,
'alexacheck' => 1
),
array( 'hoster_id' => $row['hoster_id'] ),
array(
'%d',
'%d'
),
array( '%d' )
);
}
$str.='</table>';
echo $str;
exit;
?>
$i=0;
$max=50;
$sleepTime=3;
foreach($testas$row){
$rank=(int)alexaRank($row['hoster']);
如果($rank==0)
$rank=99999999;
回声';
回显“.$row['hoster_id']”;
回显'.$row['hoster'].';
回声“.$rank.”;
回声';
$wpdb->update('fhw_filehosters',数组(
“alexa”=>$rank,
“alexacheck”=>1
),
排列(
'hoster_id'=>$row['hoster_id']
),
排列(
“%d”,
“%d”
),
数组(“%d”)
);
ii($i===$max)
{
$i=-1;
睡眠(睡眠时间);
}
$i++;
}
至少尝试一下,最好的学习方法是体验。像这样的长时间运行的流程可能适合工作队列
$page = $_GET["page"]; // I skip the validation, you should do it be yourself
require_once( dirname(__FILE__) . '/shared.php');
function tabelle_holen_hosters( $condition = "" ) {
global $wpdb;
$sql = "SELECT * FROM whatever" . $condition;
if( $table = $wpdb->get_results( $sql, ARRAY_A ) ) {
return $table;
} else {
echo "SQL ERROR in tabelle_holen()";
var_dump( $table );
return false;
}
}
function alexaRank( $url ) {
$request_url = "http://data.alexa.com/data?cli=10&url=".$url;
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml->SD->POPULARITY['TEXT'];
}
$limit = 200;
$start= $page*$limit;
$test = tabelle_holen_hosters( " WHERE working=1 AND alexacheck=0 LIMIT $start,$limit" );
$str = '<table>';
foreach ( $test as $row ){
$rank = (int) alexaRank( $row['hoster'] );
if ($rank == 0)
$rank = 999999999;
$str.= '<tr>';
$str.= '<td>' . $row['hoster_id'] . '</td>';
$str.= '<td>' . $row['hoster'] . '</td>';
$str.= '<td>' . $rank . '<td>';
$str.= '</tr>';
$wpdb->update(
'fhw_filehosters',
array(
'alexa' => $rank,
'alexacheck' => 1
),
array( 'hoster_id' => $row['hoster_id'] ),
array(
'%d',
'%d'
),
array( '%d' )
);
}
$str.='</table>';
echo $str;
exit;
?>
$page = $_GET["page"]; // I skip the validation, you should do it be yourself
require_once( dirname(__FILE__) . '/shared.php');
function tabelle_holen_hosters( $condition = "" ) {
global $wpdb;
$sql = "SELECT * FROM whatever" . $condition;
if( $table = $wpdb->get_results( $sql, ARRAY_A ) ) {
return $table;
} else {
echo "SQL ERROR in tabelle_holen()";
var_dump( $table );
return false;
}
}
function alexaRank( $url ) {
$request_url = "http://data.alexa.com/data?cli=10&url=".$url;
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml->SD->POPULARITY['TEXT'];
}
$limit = 200;
$start= $page*$limit;
$test = tabelle_holen_hosters( " WHERE working=1 AND alexacheck=0 LIMIT $start,$limit" );
$str = '<table>';
foreach ( $test as $row ){
$rank = (int) alexaRank( $row['hoster'] );
if ($rank == 0)
$rank = 999999999;
$str.= '<tr>';
$str.= '<td>' . $row['hoster_id'] . '</td>';
$str.= '<td>' . $row['hoster'] . '</td>';
$str.= '<td>' . $rank . '<td>';
$str.= '</tr>';
$wpdb->update(
'fhw_filehosters',
array(
'alexa' => $rank,
'alexacheck' => 1
),
array( 'hoster_id' => $row['hoster_id'] ),
array(
'%d',
'%d'
),
array( '%d' )
);
}
$str.='</table>';
echo $str;
exit;
?>
当应用程序进入“维护”模式时。您仍然可以使用相同的作业队列。就像上面提到的一条评论一样,您甚至可以有一个cron作业,它每天向队列发送两次作业。我通常使用函数和。这对我来说很有用。首先,将工作代码与基本代码和前端代码分开会很好,这样:
$page = $_GET["page"]; // I skip the validation, you should do it be yourself
require_once( dirname(__FILE__) . '/shared.php');
function tabelle_holen_hosters( $condition = "" ) {
global $wpdb;
$sql = "SELECT * FROM whatever" . $condition;
if( $table = $wpdb->get_results( $sql, ARRAY_A ) ) {
return $table;
} else {
echo "SQL ERROR in tabelle_holen()";
var_dump( $table );
return false;
}
}
function alexaRank( $url ) {
$request_url = "http://data.alexa.com/data?cli=10&url=".$url;
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml->SD->POPULARITY['TEXT'];
}
$limit = 200;
$start= $page*$limit;
$test = tabelle_holen_hosters( " WHERE working=1 AND alexacheck=0 LIMIT $start,$limit" );
$str = '<table>';
foreach ( $test as $row ){
$rank = (int) alexaRank( $row['hoster'] );
if ($rank == 0)
$rank = 999999999;
$str.= '<tr>';
$str.= '<td>' . $row['hoster_id'] . '</td>';
$str.= '<td>' . $row['hoster'] . '</td>';
$str.= '<td>' . $rank . '<td>';
$str.= '</tr>';
$wpdb->update(
'fhw_filehosters',
array(
'alexa' => $rank,
'alexacheck' => 1
),
array( 'hoster_id' => $row['hoster_id'] ),
array(
'%d',
'%d'
),
array( '%d' )
);
}
$str.='</table>';
echo $str;
exit;
?>
$page = $_GET["page"]; // I skip the validation, you should do it be yourself
require_once( dirname(__FILE__) . '/shared.php');
function tabelle_holen_hosters( $condition = "" ) {
global $wpdb;
$sql = "SELECT * FROM whatever" . $condition;
if( $table = $wpdb->get_results( $sql, ARRAY_A ) ) {
return $table;
} else {
echo "SQL ERROR in tabelle_holen()";
var_dump( $table );
return false;
}
}
function alexaRank( $url ) {
$request_url = "http://data.alexa.com/data?cli=10&url=".$url;
$xml = simplexml_load_file($request_url) or die("feed not loading");
return $xml->SD->POPULARITY['TEXT'];
}
$limit = 200;
$start= $page*$limit;
$test = tabelle_holen_hosters( " WHERE working=1 AND alexacheck=0 LIMIT $start,$limit" );
$str = '<table>';
foreach ( $test as $row ){
$rank = (int) alexaRank( $row['hoster'] );
if ($rank == 0)
$rank = 999999999;
$str.= '<tr>';
$str.= '<td>' . $row['hoster_id'] . '</td>';
$str.= '<td>' . $row['hoster'] . '</td>';
$str.= '<td>' . $rank . '<td>';
$str.= '</tr>';
$wpdb->update(
'fhw_filehosters',
array(
'alexa' => $rank,
'alexacheck' => 1
),
array( 'hoster_id' => $row['hoster_id'] ),
array(
'%d',
'%d'
),
array( '%d' )
);
}
$str.='</table>';
echo $str;
exit;
?>
$page=$\u GET[“page”];//我跳过验证,你应该自己做
require_once(dirname(__文件)'/shared.php');
功能表($condition=”“){
全球$wpdb;
$sql=“从任何条件中选择*”$condition;
if($table=$wpdb->get_results($sql,ARRAY_A)){
返回$table;
}否则{
echo“tabelle_holen()中的SQL错误”;
var_dump($表);
返回false;
}
}
函数名($url){
$request_url=”http://data.alexa.com/data?cli=10&url=“$url;
$xml=simplexml_load_file($request_url)或die(“提要未加载”);
返回$xml->SD->POPULARITY['TEXT'];
}
$limit=200;
$start=$page*$limit;
$test=tabelle_holen_hosters(“其中工作=1,alexacheck=0限制$start,$LIMIT”);
$str='';
foreach($testas$row){
$rank=(int)alexaRank($row['hoster']);
如果($rank==0)
$rank=99999999;
$str=