overload on server why php?

June 29, 2015 1.1k views
PHP Frameworks PHP Applications Deployment

i using this code on my server 2 GB 40 GB NYC3 connected to android app :

class DB {

private $_mysqli,$_query,$_results= array(),$_count = 0;
public static $instance;

public static function getInstance(){
self::$instance = new DB();
return self::$instance;

// Constructor
private function __construct() {
$this->_mysqli = new mysqli('localhost','root','pass','database');

public function query($sql){
while($row = $this->_query->fetch_object()){
$this->_count = $this->_query->num_rows;
return $this;

public function results(){
return $this->_results;

public function count(){
return $this->_count;

header('Content-type: application/json');
require_once 'com.php';
ini_set('memory_limit', '500M');

$result = null;
$fu = $_GET['fu'];

$json_response = array();
if($fu == 4)
$result = DB::getInstance()->query("SELECT Title,State,Year,Rate,img,Gen,time,type,allow,popu ,Rating FROM `aa` WHERE `fu`='1' OR `fu`='2' AND `popu`=1")->results();

}else if ($fu == 5)
$result = DB::getInstance()->query("SELECT Title,State,Year,Rate,img,Gen,time,type,allow,popu ,Rating FROM `zz` WHERE `fu`='3' AND `popu`=1")->results();
}else if ($fu == 2)
$result = DB::getInstance()->query("SELECT Title,State,Year,Rate,img,Gen,time,type,allow,popu ,Rating FROM zzWHERE fu=1 OR fu=2")->results();
$result = DB::getInstance()->query("SELECT Title,State,Year,Rate,img,Gen,time,type,allow,popu ,Rating FROM aaWHERE fu='$fu' ORDER BY updated_dt DESC")->results();


echo json_encode($result);


server so slow and some time not openning

please and one have idea why this ?


  • check the error log and see what's going on.

    i'm not sure but, does your code a little miss ? you had wrote two php opening tag.

    <?php<?php <<< does this proper ?

    At the sql query there is a misstypo

    Rating FROM zzWHERE


    Rating FROM aaWHERE

    see, the zz and aa are connected with WHERE. does this means the query got problem ?

    please see the error log first.

  • i made this , i just saying iam using this code my server have overload and take long time to run or to execute php script

  • can you run a DESC on the tables, and share with us? I'm thinking it's one of 2 things:

    There's no limiter on the query


    You don't have the table(s) properly indexed

  • Yes, even you made that script. please see the error log. that will make us know what's going on with the script if there is any error exist. If no error, you can do @JonsJava suggestions.


Be the first one to answer this question.