root/ext/opcache/zend_accelerator_debug.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. zend_accel_error

   1 /*
   2    +----------------------------------------------------------------------+
   3    | Zend OPcache                                                         |
   4    +----------------------------------------------------------------------+
   5    | Copyright (c) 1998-2016 The PHP Group                                |
   6    +----------------------------------------------------------------------+
   7    | This source file is subject to version 3.01 of the PHP license,      |
   8    | that is bundled with this package in the file LICENSE, and is        |
   9    | available through the world-wide-web at the following url:           |
  10    | http://www.php.net/license/3_01.txt                                  |
  11    | If you did not receive a copy of the PHP license and are unable to   |
  12    | obtain it through the world-wide-web, please send a note to          |
  13    | license@php.net so we can mail you a copy immediately.               |
  14    +----------------------------------------------------------------------+
  15    | Authors: Andi Gutmans <andi@zend.com>                                |
  16    |          Zeev Suraski <zeev@zend.com>                                |
  17    |          Stanislav Malyshev <stas@zend.com>                          |
  18    |          Dmitry Stogov <dmitry@zend.com>                             |
  19    +----------------------------------------------------------------------+
  20 */
  21 
  22 #include <stdio.h>
  23 #include <stdlib.h>
  24 #include <stdarg.h>
  25 #include <time.h>
  26 #ifdef ZEND_WIN32
  27 # include <process.h>
  28 #endif
  29 #include "ZendAccelerator.h"
  30 
  31 void zend_accel_error(int type, const char *format, ...)
  32 {
  33     va_list args;
  34         time_t timestamp;
  35         char *time_string;
  36         FILE * fLog = NULL;
  37         TSRMLS_FETCH();
  38 
  39         if (type > ZCG(accel_directives).log_verbosity_level) {
  40                 return;
  41         }
  42 
  43         timestamp = time(NULL);
  44         time_string = asctime(localtime(&timestamp));
  45         time_string[24] = 0;
  46 
  47         if (!ZCG(accel_directives).error_log ||
  48             !*ZCG(accel_directives).error_log ||
  49             strcmp(ZCG(accel_directives).error_log, "stderr") == 0) {
  50 
  51                 fLog = stderr;
  52         } else {
  53                 fLog = fopen(ZCG(accel_directives).error_log, "a+");
  54                 if (!fLog) {
  55                         fLog = stderr;
  56                 }
  57         }
  58 
  59 #ifdef ZTS
  60     fprintf(fLog, "%s (%lu): ", time_string, (unsigned long)tsrm_thread_id());
  61 #else
  62     fprintf(fLog, "%s (%d): ", time_string, getpid());
  63 #endif
  64 
  65         switch (type) {
  66                 case ACCEL_LOG_FATAL:
  67                         fprintf(fLog, "Fatal Error ");
  68                         break;
  69                 case ACCEL_LOG_ERROR:
  70                         fprintf(fLog, "Error ");
  71                         break;
  72                 case ACCEL_LOG_WARNING:
  73                         fprintf(fLog, "Warning ");
  74                         break;
  75                 case ACCEL_LOG_INFO:
  76                         fprintf(fLog, "Message ");
  77                         break;
  78                 case ACCEL_LOG_DEBUG:
  79                         fprintf(fLog, "Debug ");
  80                         break;
  81         }
  82 
  83     va_start(args, format);
  84     vfprintf(fLog, format, args);
  85     va_end(args);
  86         fprintf(fLog, "\n");
  87         switch (type) {
  88                 case ACCEL_LOG_ERROR:
  89                         zend_bailout();
  90                         break;
  91                 case ACCEL_LOG_FATAL:
  92                         exit(-2);
  93                         break;
  94         }
  95         fflush(fLog);
  96         if (fLog != stderr) {
  97                 fclose(fLog);
  98         }
  99 }

/* [<][>][^][v][top][bottom][index][help] */