медленная работа php на машине

Василий М.

Новичок
upd. соединение с mysql на локальной машине дается очень долго.

Разница во времени между этими строчками:

PHP:
print_r((microtime(true) - TIME_START)); echo "<br>";
// 0,01
$this->mysqli = @new mysqli($this->server, $this->user, $this->password, null, $this->port, $this->socket);
print_r((microtime(true) - TIME_START)); exit;
// 1,01
куда копать?
 
Последнее редактирование:

Василий М.

Новичок
Код:
@new mysqli
шел 2014 год
действительно
конструктор выдающий в stdout
Warning: mysqli::mysqli() [mysqli.mysqli]: (28000/1045): Access denied for user 'root'@'localhost' (using password: YES) in Z:\home\adverts\www\Krugozor\Database\Mysql.php on line 528
при неверном логине/пароле вместо Exception это ад и израиль.
 

Вурдалак

Продвинутый новичок
Василий М., в stdout он будет выдавать, если у тебя display_errors включено. Серьёзно что ли? А почему ты не конвертируешь ошибки в exception'ы?
 

Василий М.

Новичок
А почему ты не конвертируешь ошибки в exception'ы?
я не умею.
(не буду разводить холивар и спрашивать какого х я должен конвертировать ошибки в exceptiion и почему это не сделали разработчики пхп за меня, особенно учитывая факт того, что КЛАСС вместо исключения выдает warning, что является прямым нарушением всех оопшных догм)

PS ошибки я отключаю на продакшене, я же не совсем идиот
 
Последнее редактирование:

AnrDaemon

Продвинутый новичок
PHP:
  /** Custom error-to-exception handler
    *
    * courtesy of [email protected]
    * http://php.net/manual/en/class.errorexception.php#95415
    * As noted below [in the discussion], it's important to realize that unless
    * caught, any Exception thrown will halt the script. So converting EVERY
    * notice, warning, or error to an ErrorException will halt your script when
    * something harmlesss like E_USER_NOTICE is triggered.
    *
    * [snip]
    *
    * Setting this function as the error handler will result in ErrorExceptions
    * only being thrown for E_USER_ERROR and E_RECOVERABLE_ERROR, while other
    * enabled error types will simply get error_log()'ed.
    *
    * It's worth noting again that no matter what you do, "E_ERROR, E_PARSE,
    * E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most
    * of E_STRICT" will never reach your custom error handler, and therefore will
    * not be converted into ErrorExceptions. Plan accordingly.
    *
    * @param integer $severity PHP Error severity.
    * @param string $message Error text.
    * @param string $filename Error source file.
    * @param integer $lineno Error source line number.
    * @param mixed $context Error context.
    * @return boolean <b>FALSE</b> if error is enabled in configuration, othervise undefined.
  */
  static function errorHandler($severity, $message, $filename, $lineno, $context)
  {
    // If this error is of the enabled ones in php config (php.ini, .htaccess, etc)
    if((bool)($severity & ini_get('error_reporting')))
    {
      // -- FATAL ERROR
      // throw an Error Exception, to be handled by whatever Exception handling logic is available in this context
      if(in_array($severity, array(E_USER_ERROR, E_RECOVERABLE_ERROR)))
      {
        throw new ErrorException($message, 0, $severity, $filename, $lineno);
      }
      else if(TOOL_RETHROW_ALL)
      {
        $e = new ErrorException($message, 0, $severity, $filename, $lineno);
        print("<p>(Sev:{$e->getSeverity()}) " . htmlspecialchars($e->getMessage()) . "</p>\n");
        print("<pre>Stack trace:\n" . htmlspecialchars($e->getTraceAsString()) . "\n" .
          "  thrown in <b>" . htmlspecialchars($e->getFile()) . ":{$e->getLine()}</b></pre>\n");
        // Assuming debugging session in progress, we keep system log clean from
        // excessive error spam, forbidding error tracking since error is displayed.
        return true;
      }

      // -- NON-FATAL ERROR/WARNING/NOTICE
      // Log the error since it's enabled
      error_log($message, 0);
      // Make sure this ends up in $php_errormsg, if appropriate
      return false;
    }
  }
(Другими словами, пока PHP САМ, **!, не начнёт бросаться нормальными эксепшенами, ***** ты чего сделаешь нормально. Только костыли.)
 
Последнее редактирование модератором:
Сверху