Forum Moderators: phranque

Message Too Old, No Replies

Apache benchmark tool ab - postfile with PHP script

         

IQRules

4:35 am on Oct 16, 2008 (gmt 0)

10+ Year Member



$ ab -help
Usage: ab [options] [http://]hostname[:port]/path
Options are:
-n requests Number of requests to perform

Can I do this? The idea is read in data from post.txt and do a MySQL insert to a table.
I plan to use ab tool to do some testing.

$ab -p ./post.txt [mdd...]

$ cat insert.php
<?php
$mysqli = mysqli_connect("localhost", "joeuser", "somepass", "testDB");

if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
} else {
$sql = "INSERT INTO testTable (testField) VALUES ('".$_POST["testfield"]."')";
$res = mysqli_query($mysqli, $sql);

if ($res === TRUE) {
echo "A record has been inserted.";
} else {
printf("Could not insert record: %s\n", mysqli_error($mysqli));
}

mysqli_close($mysqli);
}

If I replace _POST to _GET here, that will work.

$ab [mdd...]

$ cat insertget.php
<?php
$mysqli = mysqli_connect("localhost", "joeuser", "somepass", "testDB");

if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
} else {
$testfield = $_GET['testfield'];
$sql = "INSERT INTO testTable (testField) VALUES ('".$testfield."')";
echo $sql ;
$res = mysqli_query($mysqli, $sql);

if ($res === TRUE) {
echo "A record has been inserted.";
} else {
printf("Could not insert record: %s\n", mysqli_error($mysqli));
}

mysqli_close($mysqli);
}
?>

[edited by: IQRules at 4:39 am (utc) on Oct. 16, 2008]