| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2011-12-23 05:59 UTC] roberto at spadim dot com dot br
 Description:
------------
hi guys, i´m running a console program, it never ends just when computer is restarted
my problem is...
some times php show a error (warning) like this:
Warning: mysql_ping(): MySQL server has gone away in /home/apache/172.16.0.254/rdm-business/system/db/database.types.spadim on line 982
the problem is... when it happened?
a good help could be a function like this:
error_messages_show_date_time($date_time_yes_no,$program_uptime)
to select if add or not date time, for example..
error_messages_show_date_time(1,0)
Warning: [2011-12-23 03:55:00 BRST] mysql_ping(): MySQL server has gone away in /home/apache/172.16.0.254/rdm-business/system/db/database.types.spadim on line 982
error_messages_show_date_time(0,0)
Warning: mysql_ping(): MySQL server has gone away in /home/apache/172.16.0.254/rdm-business/system/db/database.types.spadim on line 982
AND the second option could be:
error_messages_show_date_time(0,1)
Warning: [123455 seconds uptime] mysql_ping(): MySQL server has gone away in /home/apache/172.16.0.254/rdm-business/system/db/database.types.spadim on line 982
error_messages_show_date_time(1,1)
Warning: [2011-12-23 03:55:00 BRST, 123455 seconds uptime] mysql_ping(): MySQL server has gone away in /home/apache/172.16.0.254/rdm-business/system/db/database.types.spadim on line 982
:) this help a lot!! for web pages it´s not a big diference... just for console based programs
Test script:
---------------
any program with erros or warnings some thing like this could work:
<?php
error_messages_show_date_time(0,0);
file_get_contents("http://some_ip_that_dont_exists/some_file.txt");
sleep(10);
error_messages_show_date_time(0,1);
file_get_contents("http://some_ip_that_dont_exists/some_file.txt");
sleep(10);
error_messages_show_date_time(1,0);
file_get_contents("http://some_ip_that_dont_exists/some_file.txt");
sleep(10);
error_messages_show_date_time(1,1);
file_get_contents("http://some_ip_that_dont_exists/some_file.txt");
?>
Expected result:
----------------
at request descrition...
Actual result:
--------------
just warning without date time and program uptime
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 12:00:01 2025 UTC | 
Apart from fatal errors that won't call the custom handler, you can do this yourself via set_error_handler: set_error_handler(function($n, $str, $file, $line, $context) { if ($n & error_reporting()) { if ($n == E_WARNING || $n == E_USER_WARNING) $type = 'Warning'; else if ($n == E_NOTICE || $n == E_USER_NOTICE) $type = 'Notice'; else if ($n == E_STRICT) $type = 'Strict standards'; else $type = 'Error'; fwrite(STDERR, $type . ': [' . date('Y-m-d H:i:s T') . ']: ' . $str . ' in ' . $file . ' on line ' . $line . PHP_EOL ); } });