php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60599 ADD DATE TIME FOR CONSOLE WARNINGS
Submitted: 2011-12-23 05:59 UTC Modified: 2011-12-24 18:18 UTC
Votes:3
Avg. Score:3.0 ± 0.0
Reproduced:1 of 2 (50.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: roberto at spadim dot com dot br Assigned:
Status: Open Package: *General Issues
PHP Version: 5.4.0RC3 OS: any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: roberto at spadim dot com dot br
New email:
PHP Version: OS:

 

 [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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-23 07:32 UTC] anon at anon dot anon
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
		);
	}
});
 [2011-12-23 07:38 UTC] roberto at spadim dot com dot br
yes, that´s what i´m doing today
but in any console based php script is interesting to use it, a default 
configuration to console and apache could help a lot
today i add a file at every script i start in console with this function
it´s works, but maybe at php source could be more 'beautiful' and user friendly
 [2011-12-24 18:18 UTC] derick@php.net
Just use syslog for this. PHP can log errors to it and it will add the time and 
date for you.
 [2023-06-13 11:13 UTC] softwareappnews at gmail dot com
Software App News are sharing latest news about tech, software, social media, seo etc. More info to visit:(https://softwareappnews.com)github.com
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 04:01:31 2024 UTC