Scenario :
You want to test number of allowed parallel connections to your mysql Server .
Steps:
- Create a Database
- Create a Table
- Create a PHP insert Script
- Test the Script
- Use ab.exe tool from apache.
Create a table
CREATE TABLE `test_table` ( `id` int(11) NOT NULL, `session_id` varchar(250) DEFAULT NULL, `date_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- Indexes for table `test_table` ALTER TABLE `test_table` ADD PRIMARY KEY (`id`); -- AUTO_INCREMENT for table `test_table` -- ALTER TABLE `test_table` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
Create a PHP insert Script as follows and save as insert.php on root of your server
######################################
<?php
$servername = “localhost”;
$username = “root”;
$password = “root”;
$dbname = “testload”;
session_start();
$sessid = session_id();
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}
$sql = “INSERT INTO `test_table` (`session_id`) VALUES (‘$sessid’)”;
if ($conn->query($sql) === TRUE) {
echo “New record created successfully”;
} else {
echo “Error: ” . $sql . “<br>” . $conn->error;
}
$conn->close();
?>
######################################
Test the Script by opening from http://localhost/insert.php
Use ab.exe tool from apache. [Apache Benchmark Tool]
Change directory to apache/bin
and run below command
ab.exe -n 1000 -c 1000 http://127.0.0.1/insert.php
For more details on ab,exe please refer this website : https://httpd.apache.org/docs/2.4/programs/ab.html