echo "Create table test\n"; try { $MOO->create('test', array('id' => 'INT', 'bad_rand' => 'INT', 'name' => 'TINYTEXT'), array('AUTO_INCREMENT' => 'id', 'INDEX' => array('bad_rand'))); } catch (Exception $e) { echo "Caught exception: " . $e->getMessage() . "\n"; } usleep(1000); // sleep just a moment to ensure that table is created echo "Inserting " . INSERT_VALUES . " values\n"; for ($i = 0; $i < INSERT_VALUES; $i++) { if ($i % 50 == 0) { echo 'Inserted ' . $MOO->insert_id() . "\n"; } $br = mt_rand(0, INSERT_VALUES / AVG_BAD_RAND); //echo 'inserting br = '.$br."\n"; $MOO->insert('test', array('name' => 'entry #' . $i, 'bad_rand' => $br)); // } echo "Last insert ID: " . $MOO->insert_id() . "\n"; /*if($pid == 0) { return 0; }else { pcntl_waitpid($pid, $status); echo "Child status: $status\n"; //echo "Inserted results:\n"; //$res = ( $MOO->select('test') );
<?php include 'db.php'; echo `rm -rf test`; mkdir('test'); $db = new YNDb('test'); $db->create('cdr', array('id' => 'INT', 'cust' => 'INT', 'dt' => 'TINYTEXT'), array('AUTO_INCREMENT' => 'id', 'INDEX' => array('cust'))); date_default_timezone_set('Europe/Moscow'); for ($i = 0; $i < 25; $i++) { $db->insert('cdr', array('cust' => mt_rand(0, 4), 'dt' => date('Y-m-d H:i:s'))); sleep(mt_rand(1, 3)); }
// $db -> create(TABLE, array( 'id' => 'INT', 'data' => 'TINYTEXT', 'float' => 'DOUBLE', 'text' => 'TEXT', 'LONGTEXT' => 'LONGTEXT', 'rand' => 'INT', 'bad_rand' => 'INT' ), array('AUTO_INCREMENT' => array('name' => 'id'), 'UNIQUE' => array('rand'), 'INDEX' => array('bad_rand'))); $db->create(TABLE, array('id' => 'InT', 'data' => 'TiNYTEXT', 'float' => 'DOUBLE', 'text' => 'TEXT', 'loNgText' => 'LONGTEXT', 'rand' => 'INT', 'bad_rand' => 'INT', 'another_bad_rand' => 'INT', 'another_rand' => 'INT'), array('AUTO_INCREMENT' => 'id', 'UNIQUE' => array('rand', 'another_rand'), 'INDEX' => array('bad_rand', 'another_bad_rand'))); //echo '<p><b>ERROR (if not empty):</b> '.$db -> get_error(); break; case 'insert': ///* $start = microtime(true); echo '<!-- ' . str_repeat('-', 1024) . ' -->'; set_time_limit(0); $primary_time = $lock_time = $unique_time = $index_time = 0; $start = microtime(true); //$db->lock_table(TABLE); $i = $i8 = $ia25 = 0; while (microtime(true) - $start < 1) { try { $db->insert(TABLE, array('data' => time() . str_repeat('gh;dajfkaljfdlkjflsdaca ', 10), 'float' => M_PI * rand(), 'text' => 'проверка', 'LONGTEXT' => 'првоерка работы :)', 'rand' => mt_rand(0, 100), 'bad_rand' => $brnd = rand(0, 32), 'another_bad_rand' => $abrnd = rand(0, 90), 'another_rand' => mt_rand())); } catch (Exception $e) { echo '<b>Exception:</b> ' . $e->getMessage() . '<br/>'; continue; } //break; $i++; if ($brnd == 8) { $i8++; } if ($abrnd == 25) { $ia25++; } if ($i % 50 == 0) { echo $i . ' '; flush();