PHP Mysql vs Mysqli in windows

I am using PHP 5.3.10 in windows (Windows 7 64bits) using Apache and Mod_php.

Im in the process of deciding which library I should use, so I am testing both Mysql and MySQLi

I created two pages for the test

$mysqli = new mysqli("127.0.0.1", "root2", "secretsquirrel", "test"); for ($i=0;$i<100;$i++) { $result = $mysqli->query("SELECT * from test"); // var_dump($result); echo "ok $i"; $result->close(); } 

and

 $dbh=mysql_connect("127.0.0.1","root2","secretsquirrel",true); mysql_select_db("test",$dbh); for ($i=0;$i<100;$i++) { $result=@mysql _query("SELECT * from test",$dbh); echo "ok"; mysql_free_result($result); } 

In both tests, I can connect without any problems and receive information.

However, if I run a parallel test (5 concurrent users), MySqli is very slow.

And worst of all, if I run a parallel test (10 concurrent users), then MySQLi crashes Apache.

 Faulting application name: httpd.exe, version: 2.2.22.0, time stamp: 0x4f4a84ad Faulting module name: php5ts.dll, version: 5.3.10.0, time stamp: 0x4f2ae5d1 Exception code: 0xc0000005 Fault offset: 0x0000c7d7 Faulting process id: 0x1250 Faulting application start time: 0x01cd037de1e2092d Faulting application path: C:\apache2\bin\httpd.exe Faulting module path: C:\php53\php5ts.dll Report Id: 1fb70b72-6f71-11e1-a64d-005056c00008 

Everything works fine with MySql, even with 1000 concurrent users.

Question: Am I doing something wrong?

This is my php.ini configuration

 [MySQLi] mysqli.max_persistent = -1 ;mysqli.allow_local_infile = On mysqli.allow_persistent = On mysqli.max_links = -1 mysqli.cache_size = 2000 mysqli.default_port = 3306 mysqli.default_socket = mysqli.default_host = mysqli.default_user = mysqli.default_pw = mysqli.reconnect = Off 

ps: PDO is known to be the worst

Code: (maybe the test is wrong?)

 $dbo = new PDO("mysql:host=127.0.0.1;dbname=test", "root2", "secretsquirrel" ); for ($i=0;$i<100;$i++) { $dbo->query("SELECT * from test"); echo "ok $i"; } 

The result is worse than MySQLi

Update:

I did the same on Linux (redhat), and MysqlI / PDO is more stable.

(1000 simultaneous calls, with fewer differences).

Amount of the module (ms) Min. (ms) Max. (ms)

MySQLi 66986 265 1762

MySQL 64521 234 1388

PDO 75 426 249 1809

(minus is better).

Well, apparently, there is no answer, under the MysqlI and PDO windows there is no big one (if only in the development process). For linux, three are the same, but for a popular server (many simultaneous users), Mysql is the best, MysqlI is close (3% slower), and PDO is large (+ 10% slower).

However, this is not a real test, so mileage may vary. However, the results are consistent with popular opinion, Mysql> Mysqli> pdo.

+4
source share
2 answers

The only feature in mysqli that needs to matter is parameterized queries. The mysql interface doesn’t have them, which means that you will interpolate the values ​​into the queries yourself, and this, in turn, means that you have great potential for SQL injection vulnerabilities - it just turns out that ensuring query concatenation is not so trivial how does this sound.

By the way, did you consider PDO? It offers the same functions as mysqli, but can connect to any of the supported (and configured) databases, so if at any time you decide to switch to, say, PostgreSQL, SQLite or SQL Server, you only have dialect dialogs SQL is a worry, rather than porting everything to another API.

+1
source

Apache may not support everything, I ran into a lot of problems with respect for encryption and decryption of passwords with respect for Apache, but found a solution for hosting it on IIS ...

Try running the application in IIS ... http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis/ will help you use PHP on IIS 7 ... http://www.websitehosting.com/apache-vs-iis-web-server/ will clear the difference between Apache and IIS with respect to PHP ...

0
source

Source: https://habr.com/ru/post/1401814/


All Articles