I have a rather long loop running in a function, but it does not end all possible iterations and stops without any errors:
function my_function(){
foreach (range(100,999) as $art_id){
$current++;
outputProgress($current, $art_id );
}
}
I use some output using flush to track progress
function outputProgress($current, $total) {
// echo "<span style='background:red;font-size:1.5em;color:#fff;'>" . round($current / $total * 100) . "% </span>";
echo "<span style='background:red;font-size:1.5em;color:#fff;'>" . $current .'/'. $total . "% </span>";
myFlush();
sleep(1);
}
and
function myFlush() {
echo(str_repeat(' ', 256));
if (@ob_get_contents()) {
@ob_end_flush();
}
flush();
}
(do not count the percentage calculation, now it is disabled and just shows the iteration id)
I noticed that most of the time I do a loop, It just stops after 20-25 iterations. sometimes only 10.
My first suspects were time limitand max_execution time, therefore, I added:
set_time_limit(99999);
ini_set('max_execution_time', 99999);
function my_function(){
foreach (range(410,499) as $art_id){
set_time_limit(99999);
ini_set('max_execution_time', 99999);
}
}
As you can see, I added both of these INSIDEand OUTSIDEthe functions themselves just in case.
But that doesnβt help much, and the cycle still stops. My next suspect was Memory limit, so I added:
ini_set('memory_limit','128M');
wp,
define('WP_MEMORY_LIMIT', '128M');
. - .
, script , .
EDIT ββ
script , scrap_slashdot() simplehtmldom.
, Wordpress, .
EDIT II
@Allendar echo ini_get('memory_limit'); , , 128M..