PHP スクリプト自体 (セキュリティの問題は無視してください) は、これを予想される負荷にスケールアップする際に問題になることはほとんどありません。インフラストラクチャは重要であり、このスクリプトが期待する負荷に対して機能するかどうかの違いになります。
MySQL インスタンスは 1 秒あたり 1000 の新しい接続をサポートできますか? Web サーバーはこのスクリプトを 1 秒間に 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
ブートノート:学ぶべきことはたくさんあるでしょう... うまくいけば、これがあなたを始めさせ、あなたが探している負荷を比較的簡単にサポートできるようになることを願っています. そうでない場合は、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/