Skip to content

Instantly share code, notes, and snippets.

@MacoTasu MacoTasu/parallel.php

Last active Nov 2, 2016
Embed
What would you like to do?
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
You can’t perform that action at this time.