Example #1
0
<?php

require_once '../../MPLT.php';
$timer = new MPLT();
require_once '../../src/dalmp.php';
# ------------------------------------------------------------------------------
$user = getenv('MYSQL_USER') ?: 'root';
$password = getenv('MYSQL_PASS') ?: '';
$host = getenv('MYSQL_HOST') ?: '127.0.0.1';
$port = getenv('MYSQL_PORT') ?: '3306';
$db = new DALMP\Database("utf8://{$user}:{$password}@{$host}:{$port}/dalmp");
foreach ($db->GetCol('SHOW TABLES') as $table) {
    $rs = $db->Execute("OPTIMIZE TABLE {$table}");
    echo "optimizing {$table}: {$rs}", PHP_EOL;
    $rs = $db->Execute("REPAIR TABLE {$table} QUICK");
    echo "repairing {$table}: {$rs}", PHP_EOL;
}
# ------------------------------------------------------------------------------
echo PHP_EOL, str_repeat('-', 80), PHP_EOL, 'Time: ', $timer->getPageLoadTime(), ' - Memory: ', $timer->getMemoryUsage(1), PHP_EOL, str_repeat('-', 80), PHP_EOL;
Example #2
0
<?php

require_once '../../MPLT.php';
$timer = new MPLT();
require_once '../../src/dalmp.php';
# ------------------------------------------------------------------------------
$user = getenv('MYSQL_USER') ?: 'root';
$password = getenv('MYSQL_PASS') ?: '';
$host = getenv('MYSQL_HOST') ?: '127.0.0.1';
$port = getenv('MYSQL_HOST') ?: '3306';
/**
 * Cache engine defined on DSN
 */
$db = new DALMP\Database("utf8://{$user}:{$password}@{$host}:{$port}/dalmp?redis:127.0.0.1:6379");
$db->FetchMode('ASSOC');
/**
 * Cache for 5 minutes, group A
 */
$rs = $db->CachePGetAll(300, 'SELECT * FROM Country WHERE Region = ?', 'Caribbean', 'group:A');
echo count($rs), PHP_EOL;
$timer->setMark('300');
/**
 * Cache for 1 day (86400 seconds), group B
 */
$rs = $db->CachePGetAll(86400, 'SELECT * FROM Country WHERE Continent = ?', 'Europe', 'group:B');
echo count($rs), PHP_EOL;
$timer->setMark('86400');
/**
 * Cache for 1 hour (default), group C
 */
$rs = $db->CachePGetAll('SELECT * FROM Country WHERE Population <= ?', 100000, 'group:C');
Example #3
0
File: X.php Project: nbari/DALMP
<?php

require_once '../../MPLT.php';
$timer = new MPLT();
require_once '../../src/dalmp.php';
# ------------------------------------------------------------------------------
$di = new DALMP\DI();
$user = getenv('MYSQL_USER') ?: 'root';
$password = getenv('MYSQL_PASS') ?: '';
$host = getenv('MYSQL_HOST') ?: '127.0.0.1';
$port = getenv('MYSQL_PORT') ?: '3306';
$db = $di->database("utf8://{$user}:{$password}@{$host}:{$port}/dalmp");
$db->debug();
echo 'connect ', var_dump($db->connect());
sleep(3);
echo 'ping: ', var_dump($db->X()->ping());
echo 'thread_safe: ', var_dump($db->X()->thread_safe());
echo 'client_info: ', var_dump($db->X()->get_client_info());
echo 'client_version: ', var_dump($db->X()->client_version);
echo 'server_info: ', var_dump($db->X()->server_info);
echo 'server_version: ', var_dump($db->X()->server_version);
echo $timer->isCli(1), $db, $timer->isCli(1);
echo $timer->isCli(1), $db->GetOne('SELECT NOW()'), $timer->isCli(1);
$db->closeConnection();
echo 'is connected: ', var_dump($db->isConnected());
sleep(3);
echo 'ping: ', var_dump($db->X()->ping());
echo $timer->isCli(1), $db->GetOne('SELECT NOW()'), $timer->isCli(1);
sleep(3);
# ------------------------------------------------------------------------------
echo PHP_EOL, str_repeat('-', 80), PHP_EOL, 'Time: ', $timer->getPageLoadTime(), ' - Memory: ', $timer->getMemoryUsage(1), PHP_EOL, str_repeat('-', 80), PHP_EOL;
Example #4
0
<?php

require_once '../../MPLT.php';
$timer = new MPLT();
require_once '../../src/dalmp.php';
# ------------------------------------------------------------------------------
/**
 * memcache cache instance
 */
$memcache = new DALMP\Cache(new DALMP\Cache\Memcache());
/**
 * redis cache instance
 */
$redis = new DALMP\Cache(new DALMP\Cache\Redis());
/**
 * disk cache instance
 */
$disk = new DALMP\Cache(new DALMP\Cache\Disk());
/**
 * database instance
 */
$user = getenv('MYSQL_USER') ?: 'root';
$password = getenv('MYSQL_PASS') ?: '';
$host = getenv('MYSQL_HOST') ?: '127.0.0.1';
$port = getenv('MYSQL_PORT') ?: '3306';
$db = new DALMP\Database("utf8://{$user}:{$password}@{$host}:{$port}/dalmp");
$sql = 'SELECT * FROM Country LIMIT 2';
/**
 * Cache for 5 minutes with key: mykey using memcache cache
 */
$db->useCache($memcache);
Example #5
0
<?php

error_reporting(-1);
require_once '../../MPLT.php';
$timer = new MPLT();
require_once '../../src/dalmp.php';
# ------------------------------------------------------------------------------
$user = getenv('MYSQL_USER') ?: 'root';
$password = getenv('MYSQL_PASS') ?: '';
$host = getenv('MYSQL_HOST') ?: '127.0.0.1';
$port = getenv('MYSQL_PORT') ?: '3306';
/**
 * path of the queue
 */
define('DALMP_QUEUE_DB', '/tmp/queue.db');
# optional if you want to encrypt the sqlite db
#define('DALMP_SQLITE_ENC_KEY', 'na1ujhrjhqev{5#nyxx~oaV9aqrf3kll');
$db = new DALMP\Database("utf8://{$user}:{$password}@{$host}:{$port}/dalmp");
/**
 * In case something goes wrong, the database is unavailable, fields missing,  etc, you can save 'sql query' and later process it again.
 */
$sql = "INSERT INTO testX SET colA=(NOW())";
try {
    $rs = $db->Execute($sql);
} catch (\Exception $e) {
    $db->queue($sql, 'my-queue');
}
/**
 * Save some $_POST/$_GET data in json format
 */
$get = array('uuid' => $db->UUID(), 'cdate' => @date('c'), 'field1' => 1, 'field2' => 2);
Example #6
0
<?php

require_once '../../MPLT.php';
$timer = new MPLT();
require_once '../../src/dalmp.php';
# ------------------------------------------------------------------------------
$user = getenv('MYSQL_USER') ?: 'root';
$password = getenv('MYSQL_PASS') ?: '';
$host = getenv('MYSQL_HOST') ?: '127.0.0.1';
$port = getenv('MYSQL_PORT') ?: '3306';
$db = new DALMP\Database("utf8://{$user}:{$password}@{$host}:{$port}/dalmp");
/**
 *  load zone files to mysql
 *  mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
 */
$db->PExecute('SET time_zone=?', '+00:00');
$db->FetchMode('ASSOC');
$sql = 'SELECT Name, Continent FROM Country WHERE Population > ? AND Code LIKE ? LIMIT ?';
$rs = $db->PGetAll($sql, 10000000, '%P%', 2);
print_r($rs);
$rs = $db->Execute('DROP TABLE IF EXISTS `tests`');
$rs = $db->Execute('CREATE TABLE `tests` (id INT(11) unsigned NOT NULL AUTO_INCREMENT, col1 varchar(255), col2 varchar(255), col3 varchar(255), status iNT(1), PRIMARY KEY (id))');
$rs = $db->AutoExecute('tests', array('col1' => 'ai eu', 'col2' => 2, 'status' => 0));
/**
 * status value is 0 or 1 on table
 * NOTICE the use of ===
 */
$sql = 'SELECT status FROM tests WHERE id=?';
$rs = $db->PgetOne($sql, 3);
if ($rs === false) {
    echo "no result" . $timer->isCli(1);
Example #7
0
<?php

require_once '../../MPLT.php';
$timer = new MPLT();
require_once '../../src/dalmp.php';
# ------------------------------------------------------------------------------
/**
 * sqlite queue instance
 */
$queue = new DALMP\Queue(new DALMP\Queue\SQLite('/tmp/dalmp_queue.db'));
echo 'enqueue status: ', var_dump($queue->enqueue('this is a teste')), $timer->isCli(1);
echo 'dequeue all: ', print_r($queue->dequeue(), true), $timer->isCli(1);
echo 'dequeue only 3: ', print_r($queue->dequeue(3), true), $timer->isCli(1);
echo 'delete from queue: ', var_dump($queue->delete(63)), $timer->isCli(1);
# ------------------------------------------------------------------------------
echo PHP_EOL, str_repeat('-', 80), PHP_EOL, 'Time: ', $timer->getPageLoadTime(), ' - Memory: ', $timer->getMemoryUsage(1), PHP_EOL, str_repeat('-', 80), PHP_EOL;
Example #8
0
<?php

require_once '../../MPLT.php';
$timer = new MPLT();
require_once '../../src/dalmp.php';
# ------------------------------------------------------------------------------
$timer->setMark('start');
$user = getenv('MYSQL_USER') ?: 'root';
$password = getenv('MYSQL_PASS') ?: '';
$host = getenv('MYSQL_HOST') ?: '127.0.0.1';
$port = getenv('MYSQL_PORT') ?: '3306';
$db = new DALMP\Database("utf8://{$user}:{$password}@{$host}:{$port}/dalmp");
$db->FetchMode('NUM');
$sql = 'SELECT * FROM City';
$rs = $db->Execute($sql);
if ($rs) {
    while (($rows = $db->query()) != false) {
        list($r1, $r2, $r3) = $rows;
        echo "w1: {$r1}, w2: {$r2}, w3: {$r3}", $timer->isCli(1);
    }
}
$timer->setMark('while');
/**
 * doing the same but consuming more memory.
 * Below the returned $rs2 array is not referential. Because of that, the system
 * will use excesive memory. With large columns.
 */
$rs2 = $db->GetAll($sql);
foreach ($rs2 as $value) {
    list($r1, $r2, $r3) = $value;
    echo "f1: {$r1}, f2: {$r2}, f3: {$r3}", $timer->isCli(1);