<?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'];
}
I have this script, I use the wordpress database class without wordpress. I limited the rows to 200 because else i run into problems like the pageload takes years and maybe php execution time the xml from the alexa functions takes very long. I have a lot of urls to be checked in that database and I want to update them all with one action, meaning removing the 200 limit. What would i have to do to make it like doing 50 at a time, then output and then continue? Ajax? how would I do that?
Update 1:
As i said in comments i am looking for something to make this happen (in the background) of my website, i am actually not really sure if it comes to php execution time limit at this point, but for the "all at once" solution i just tested flush() at the end of the queue and it's not working!
But I am looking for a routine function now I updated the Question, the answers are very generic and I am not that exp. I would love to get see some actually code. If thats too much and tends to be a "write me a program" then I have to figure this out by digging in some time. I will then accept the answer that help best.