Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP slow with mysqli

Tags:

php

mysql

mysqli

I (hope) this is a very straightforward question about what is being missed for PHP/MySQL. First, the computers are Windows 7 machines and are running XAMPP (Apache, PHP, MySQL, etc.) - nothing Windows/IIS, etc.

The machines are quick, with PHP & MySQL running super-fast. However, there is one machine where the way it works with PHP & MySQL is some kind of delay - specifically, it is essentially 3 seconds. In fact, if you remove EVERYTHING the code is doing so that it is doing NOTHING more than setting up its connection like this:

$db = new mysqli($hostname, $username, $password, $database);

...and there is no query or anything - just this PHP line that sets up the object, it takes exactly 3 seconds.

You comment out this line, by contrast, and the page is instant.

Anyway idea why this is happening? It doesn't look like anything is wrong, exactly, just somehow set up on this 3 seconds that we'd like to get rid of. Thanks!

like image 255
user2188580 Avatar asked Mar 19 '13 22:03

user2188580


People also ask

Is MySQLi faster than MySQL?

The installation process with MySQLi not only easy, but is automatic when the PHP5 MySQL package is installed in Windows or Linux. MySQLi performs (slightly) faster than its competition. With non-prepared statements, the system performs ~2.5% faster, and ~6.5% faster with prepared ones.

Is MySQLi deprecated in PHP 7?

The oldest one uses the MySQL extension, which was deprecated as of PHP 5.5 and fully removed in PHP 7. The mysql() function no longer works in PHP 7. It has been replaced with mysqli().

Which of the below is a PHP MySQLi function that gives you the number of results from a query?

PHP mysqli_num_rows function The mysqli_num_rows function is used to get the number of rows returned from a select query. It has the following syntax.

Which function is used to connect to a MySQLi database in PHP?

The connect() / mysqli_connect() function opens a new connection to the MySQL server.


1 Answers

If this is hosted locally and you are using localhost this will be your problem, try using

$db = new mysqli('127.0.0.1', $username, $password, $database);

This is because of how MYSQLI handles localhost and IPV6.

like image 164
Kyle Needham Avatar answered Sep 22 '22 02:09

Kyle Needham