function cron_verifyTiezi() { global $m; $set = unserialize(option::get('plugin_verifyTiezi')); $today = date("Y-m-d"); //准备:扫描verifyTiezi表中lastdo不是今天的,然后更新verifyTiezi_data表的remain $sy = $m->query("SELECT * FROM `" . DB_PREFIX . "verifyTiezi` WHERE `lastdo` != '{$today}';"); while ($sx = $m->fetch_array($sy)) { $m->query('UPDATE `' . DB_NAME . '`.`' . DB_PREFIX . 'verifyTiezi_data` SET `remain` = \'' . $sx['num'] . '\' WHERE `uid` = ' . $sx['uid']); $m->query('UPDATE `' . DB_NAME . '`.`' . DB_PREFIX . 'verifyTiezi` SET `lastdo` = \'' . $today . '\' WHERE `uid` = ' . $sx['uid']); } //开始:计划任务 $count = $m->once_fetch_array("SELECT COUNT(*) AS `c` FROM `" . DB_PREFIX . "verifyTiezi_data` WHERE `remain` > '0' LIMIT {$set['rem']};"); if ($count['c'] == $set['rem']) { $y = rand_row(DB_PREFIX . 'verifyTiezi_data', 'id', $set['rem'], "`remain` > '0'"); } else { $y = rand_row(DB_PREFIX . 'verifyTiezi_data', 'id', $count['c'], "`remain` > '0'"); } //如果只有一条记录的兼容方案 if (isset($y['url'])) { $y = array(0 => $y); } foreach ($y as $x) { if (!empty($x['pid']) && !empty($x['uid'])) { $u = $m->once_fetch_array("SELECT * FROM `" . DB_PREFIX . "verifyTiezi` WHERE `uid` = '{$x['uid']}'"); $cont = unserialize($u['cont']); $remain = $x['remain'] - 1; $res = verifyTiezi_send($x['uid'], $x['url'], $x['pid'], rand_array($cont), $set['device']); $m->query('UPDATE `' . DB_NAME . '`.`' . DB_PREFIX . 'verifyTiezi_data` SET `remain` = \'' . $remain . '\',`status` = \'' . $res['status'] . '\',`msg` = \'' . $res['msg'] . '\' WHERE `url` = \'' . $x['url'] . '\' AND `uid` = ' . $x['uid']); sleep($set['sleep']); } } }
echo $array[$i]; } else { echo $array[$i] . ", "; } } echo "]<br/>"; } function rand_array($size, $min, $max) { $array_aleatorio = []; for ($i = 0; $i < $size; $i++) { $array_aleatorio[$i] = rand($min, $max); } return $array_aleatorio; } $num_array = rand_array(1000, 0, 1000); print_array($num_array); echo "<br> - Aplicación da función de ordenación bubble:<br/>"; $time_pre = microtime(true); $num_array_ordenado_1 = sort_bubble($num_array); print_array($num_array_ordenado_1); $time_post = microtime(true); echo "Tempo de execución: " . ($time_post - $time_pre) . " s"; echo "<br/><br/>----------------------------<br/>"; echo "<br> - Aplicación da segunda función de ordenación:<br/>"; $time_pre = microtime(true); $num_array_ordenado_2 = sort_other($num_array); print_array($num_array_ordenado_2); $time_post = microtime(true); echo "Tempo de execución: " . ($time_post - $time_pre) . " s"; ?>
return $tmp_arr; } function cal_probability($search) { global $res, $arr_size; preg_match_all('/' . $search . '/', $res, $alpha); return count($alpha[0]) . '%'; } $res = ''; $arr = array(); $arr_size = 100; for ($i = 0; $i < $arr_size; $i++) { switch (true) { case $i < 30: $arr[] = 'a'; break; case $i > 31 && $i < 60: $arr[] = 'b'; break; default: $arr[] = 'c'; } } $arr = rand_array($arr); for ($i = 0; $i < $arr_size; $i++) { $res .= $arr[rand(0, 99)]; } echo 'result: ', $res, PHP_EOL; echo '<a> count: ', cal_probability('a'), PHP_EOL; echo '<b> count: ', cal_probability('b'), PHP_EOL; echo '<c> count: ', cal_probability('c'), PHP_EOL;