Good suggestions. The fastest connection to mysql (if you're using
mysql, of course) will likely be via the mysqli extension API, and
with the mysqlnd driver. PDO is quite lightweight, though, so it
probably isn't a big slowdown point for you. It will use the mysqlnd
driver if you have it installed.

http://php.net/manual/en/book.mysqli.php
http://forge.mysql.com/wiki/PHP_MYSQLND

If you're doing the same inserts with different data multiple times
per script execution, you definitely want to use prepared statements.
If the driver supports it natively, you should get a speed increase
because the db engine won't have to do an analyze/compile/optimize
step on every insert.

http://php.net/manual/en/pdo.prepared-statements.php

Also, if you have a set of inserts that will happen during a single
script execution, you might look at disabling auto-commit and using
transactions + a final commit at the end. This should speed up the
time spent inserting data considerably.

--
Ed Finkler
http://funkatron.com
AIM: funka7ron
ICQ: 3922133
Skype: funka7ron


On Sat, Nov 15, 2008 at 11:47 AM, fastest963 <[EMAIL PROTECTED]> wrote:
>
> PHP Optimizations
>
> PDO (http://www.php.net/pdo) is a must! Speeds up database
> transactions
>
> 1) Store as much data as possible into database
> 2) Store data as arrays for each updating and fetching (see serialize)
> 3) Always use an index field in mysql
> 4) Limit echos/prints
>
> Most Important: If connecting to pages (ex. API calls) use CURL Multi
> Connects
> (http://www.ibuildings.com/blog/archives/811-Multithreading-in-PHP-
> with-CURL.html) (use 2nd example)
>
> Also try to make use of Forking (http://immike.net/blog/2007/04/08/
> fork-php-and-speed-up-your-scripts/)
>
> MYSQL Optimizations
>
> 1) Use BIGINT 255 unsigned fields for ids or anything that could get
> really large
> 2) Remember OPTIMIZE
>
>
> Finally, if you are storing a lot of data. Do the following:
> Take the ID (index), hopefully not a number, and md5 it.
> Then store into a specific table based on the first letter of the md5.
> Example:
>
> $user = "fastest963"; //store user
> $let = md5($user); //md5 username
> "SELECT * FROM".$let[0]."users WHERE `username` = '$user' "; //$let[0]
> is the first letter of the md5
>
> Tables would be created like this:
> First make "0users" table. Then copy and make 1-F tables.
> 0users, 1users, 2users, 3users, 4users, 5users, 6users, 7users,
> 8users, 9users, ausers, busers, cusers, dusers, eusers, fusers
> Those would be all the table names, thus splitting your data per table
> by 16.
>
>
> I hope that helps people out when optimizing their scripts. These have
> allowed me to process 2000+ tweets per sec via PHP. Any questions?
> Feel free to comment!
>
> Thanks,
> James Hartig

Reply via email to