Skip to content

Instantly share code, notes, and snippets.

@MacoTasu
Last active November 2, 2016 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MacoTasu/c313e8dc47a4af204907bb7dbd773d25 to your computer and use it in GitHub Desktop.
Save MacoTasu/c313e8dc47a4af204907bb7dbd773d25 to your computer and use it in GitHub Desktop.
n並列で同時にqueryを発行する君( ref.https://github.com/hironobu-s/parallel-for)
<?php
require('./ParallelFor.php');
system('date');
$executor = function($var) {
$link = mysql_connect('127.0.0.1:3306', 'root', '');
if (!$link) {
die('接続できませんでした: ' . mysql_error());
}
print '接続に成功しました';
$db_selected = mysql_select_db('test', $link);
if (!$db_selected){
die('データベース選択失敗です。'.mysql_error());
}
for ($i=0; $i<=10000; $i++) {
$test = mysql_query("INSERT INTO `test` (`uid`,`count`) VALUES ('test', 1) ON DUPLICATE KEY UPDATE `count` = `count` + 1;");
if (!$test) {
print mysql_error()."\n";
}
}
mysql_close($link);
};
$p = new ParallelFor;
$p->setNumChilds(8);
$p->run(array(10000), $executor);
system('date');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment