你的PHP腳本本身(忽略任何安全問題)會不會是這個比例最多的一個問題你期望的負載。您的基礎設施將此事使這劇本,你想到還是沒有負載工作之間的差別。
您的MySQL實例能否每秒支持1000個新連接?您的Web服務器可以每秒運行該腳本1000次嗎?
解決這個問題的唯一方法是基準它找出你在哪裏,你可以支持哪些負載?如果你不能支持它,那麼你需要找到的瓶頸,但我懷疑它會永遠是這個腳本。
響應您的評論更新,最好的辦法是模擬你期望的負載,沒有一點擔心,如果你的安裝可以處理這個問題。如果它無法處理它,那麼你需要縮小這個問題的範圍。
首先,下載像Apache JMeter的工具。有一些教程可以幫助您設置模擬來嘗試您的設置。
從這裏您可以計算出問題的範圍,如果您可以支持超過您期望的流量,您可能不必擔心。如果你能只是支持它,或者你是一個很長的路要走,你需要找到它們阻止你達到這個目標的瓶頸。
通過分別測試系統的各個部分來縮小問題的範圍,這就是您回答諸如Web服務器或數據庫支持的連接數量等問題的地方。一旦確定了瓶頸,怎樣從處理更多的流量停止你的原因,你就可以有一個你需要做什麼更好的主意。
使用Apache JMeter的:
http://www.davegardner.me.uk/blog/2010/09/23/effective-load-testing-with-apache-jmeter/
使用mysqlslap加載測試MySQL:
http://dev.mysql.com/doc/refman/5.1/en/mysqlslap.html
Bootnote:有可能會是一個很多東西需要學習......希望這將讓你開始你可以相對輕鬆地支持你正在尋找的負載。如果不是,它需要大量的關於Web服務的可擴展體系結構的閱讀,您正在使用的系統的高級配置以及耐心等等。
使用PDO
//Connect to mysql server
$host = ""; // Your database host name
$driver = "mysql";
$database = ""; // Your database;
$user = ""; // The user for the database;
$password = ""; // The password for the database;
// Create a DSN string from the above parameters
$dsn = "$driver:host=$host;dbname=$database";
// Create a connection you must have the pdo_mysql
// extension added to your php.ini
try {
$db = new PDO($dsn, $user, $password);
// The connection could not be made
} catch(PDOException $ex)
die("Could not connect to server: {$ex->getMessage()}");
}
// Prepare an insert statement
$stmt = $db->prepare("
INSERT INTO `mytable` (`id`, `type`, `data`)
VALUES (:id, :type, :data)
");
// I'm guessing at the types here, use the reference
// http://php.net/manual/en/pdo.constants.php to
// select the right datatypes. Using parameter binding
// you ensure that the value is converted and escaped
// correctly for the database
$stmt->bindParam(":id", $id, PDO::PARAM_INT);
$stmt->bindParam(":type", $type, PDO::PARAM_STR);
$stmt->bindParam(":data", $data, PDO::PARAM_LOB);
// Execute the insert statement
$stmt->execute();
// Prepare a select data
$stmt = $db->prepare("
SELECT *
FROM `mytable`
WHERE `type` = :type
ORDER BY `id` DESC
LIMIT 10
");
// Again bind the parameters
$stmt->bindParam(":type", $type, PDO::PARAM_STR);
// Execute the select statement
$stmt->execute();
// There are different ways that fetch can return
// a row, the web page above lists all of the
// different types of fetch as well. In this case
// we are fetching the rows as associative arrays
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
// Write XML for rows
}
// Finalise and output XML response
使用PDO:
http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/
開始刪除你的mysql的使用並移動到mysqli –