Tag Archives: php

PHP big arrays performance issues

Merge arrays
0.011364 seconds – array_merge
0.122704 seconds – array_merge + array_unique
0.003010 seconds – array1 + array2
0.051177 seconds – array1 + array2 + array_unique

Intersect arrays
0.091835 seconds – array_intersect
0.001862 seconds – array_intersect_key

Find in arrays
1.833008 seconds – in_array
0.002288 seconds – isset
0.003777 seconds – array_key_exists

Continue reading PHP big arrays performance issues

Functie php pentru yahoo messenger availability

Poate mai ii trebuie cuiva 🙂

function isOnlineOnYahoo($yahoo_id, $timeout = 3) {
if (empty($yahoo_id)) {
return false;
}

$fbuf = “”;

$old = ini_set(‘default_socket_timeout’, $timeout);
$stath = @fopen(‘http://opi.yahoo.com/online?u=’.$yahoo_id.’&m=a&t=1′, ‘r’);
ini_set(‘default_socket_timeout’, $old);

if (is_resource($stath)) {
stream_set_timeout($stath, $timeout);
stream_set_blocking($stath, 0);

while (!feof($stath)) {
$fbuf .= fread($stath, 1024);
}

fclose($stath);
}

return ($fbuf == “01” ? true : false);
}

Oempro, subscriber lists and MYSQL synchronization

Oempro stie sa faca sincronizarea listelor cu o baza de date mysql. Numai ca nu stie sa faca dezabonarile clientilor care NU mai sunt in baza de date cu care se sincronizeaza.
Un mic tweak este sa ii dezabonezi pe toti, pentru ca de abonat se ocupa cronul de sincronizare.

Cod de bagat in cron inainte de sincronizare:

<?php

# define connection info
define(‘HOST’, ”);
define(‘USERNAME’, ”);
define(‘PASSWORD’, ”);
define(‘DBNAME’, ”);

$link = mysql_connect(HOST, USERNAME, PASSWORD) or die(“Could not connect: ” . mysql_error($link));
mysql_select_db(DBNAME, $link) or die(“Could not select db: ” . mysql_error($link));

$res = mysql_query(“SHOW TABLES”, $link);

$tables = array();

while($row = mysql_fetch_array($res)) {
if (!empty($row[0])) {
$tables[] = $row[0];
}
}

foreach ($tables as $table) {
if (strpos($table, ‘oempro_subscribers_’) !== false) {
mysql_query(“UPDATE {$table} SET SubscriptionStatus = ‘Opt-In Pending'”, $link);
echo “Table updated: {$table}\n”;
}
}

echo “Done”;

?>

That’s all.