Last active
November 2, 2016 03:51
-
-
Save MacoTasu/c313e8dc47a4af204907bb7dbd773d25 to your computer and use it in GitHub Desktop.
n並列で同時にqueryを発行する君( ref.https://github.com/hironobu-s/parallel-for)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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