10

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!

Daniel Hedberg
  • 5,677
  • 4
  • 36
  • 61
user2188580
  • 101
  • 1
  • 3
  • 2
    Is the mysql server on the same host as the machine? – Explosion Pills Mar 19 '13 at 22:39
  • are you using localhost or the network public IP of the computer to connect mysql? – Sebas Mar 19 '13 at 22:40
  • Try setting up MySQL on another machine on the same LAN. Then connect the problematic web server to this new db server, using its IP address, and see if the delay persists. This will help narrow it down to either the PHP installation or the MySQL installation. – halfer Mar 19 '13 at 22:44
  • See http://stackoverflow.com/questions/3715925/localhost-vs-127-0-0-1 – John Carter Mar 19 '13 at 23:33

2 Answers2

9

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.

Kyle Needham
  • 3,379
  • 2
  • 24
  • 38
-2
$orig = $_GET['orig'];
$des_id = $_GET['des_id'];
try {
    $dbuser = "kim";
    $dbpass = "kim";
    $conn = new  PDO('mysql:host=localhost;dbname=destination', $dbuser, $dbpass);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);    
    $stmt = $conn->prepare("SELECT pl_id FROM view_places WHERE name = :name LIMIT 1");

    $stmt->bindParam(':name',$orig); 
    $stmt->execute();
    $result_1 = $stmt -> fetch();
    $res1 = $result_1["pl_id"];  

    $stmt->bindParam(':name', $des_id); 
    $stmt->execute(); 
    $result_2 = $stmt -> fetch(); 
        $res2 = $result_2["pl_id"];  
        echo   'origin_number:'.$res1. ', '.'destination_id:'.$res2;
    }   catch(PDOException $e) {
            echo 'ERROR: ' . $e->getMessage();
    }
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
jake
  • 195
  • 1
  • 2
  • 10