Mais conteúdo relacionado Semelhante a Falhando miseralvelmente com PHP (20) Mais de Augusto Pascutti (17) Falhando miseralvelmente com PHP3. A página ta toda em branco
aqui, de novo.
Usuário do sistema
4. Como eu faço pro PHP não
exibir esse monte de
E_NOTICE chato?
Desenvolvedor querendo fazer merda
9. Since the beginning, life has
relied upon the transmission of
messages.
RFC 3164:The BSD syslog Protocol
11. Severidades:
• Emergency: deu merda. Sistema inutilizado
• Alert: vai da merda. Faça alguma coisa logo
• Critical: tem tudo pra dar merda
• Error: coisas que não deveriam acontecer
• Warning: aviso.Tome mais cuidado
• Notice: normal, mas ainda assim significativo
• Informational
• Debug
21. Um arquivo de log é como uma
mulher: quanto mais gostosa(o),
mais atenção você presta.
Newton
22. Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"
123.125.68.79 - - [20/Jun/2012:19:53:24 +0200] "GET / HTTP/1.1" 200 625 "-" "Mozilla/5.0 (compatible;
Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"
178.154.210.252 - - [20/Jun/2012:19:54:10 +0200] "GET /?C=S;O=A HTTP/1.1" 200 663 "-" "Mozilla/5.0
(compatible; YandexBot/3.0; +http://yandex.com/bots)"
74.125.126.102 - - [20/Jun/2012:20:15:28 +0200] "GET / HTTP/1.1" 200 606 "http://www.google.com/url?
sa=t&rct=j&q=error&source=web&cd=1&ved=0CFAQFjAG&url=http%3A%2F%2Fwww.isrolab.com
%2F&ei=GxPiT5PsL4e04AHPtgE&usg=AFQjCNHnmjmdkUV584ORIpOXz7zAPX0UHQ" "Mozilla/4.0 (compatible; MSIE 7.0; Windows
NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; InfoPath.2; .NET
CLR 3.0.4506.2152; .NET CLR 3.5.30729)"
74.125.126.103 - - [20/Jun/2012:20:15:29 +0200] "GET /icons/blank.gif HTTP/1.1" 200 383 "http://
www.isrolab.com/" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR
2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; InfoPath.2; .NET CLR 3.0.4506.2152; .NET CLR
3.5.30729)"
74.125.126.93 - - [20/Jun/2012:20:15:29 +0200] "GET /icons/folder.gif HTTP/1.1" 200 460 "http://
www.isrolab.com/" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR
2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; InfoPath.2; .NET CLR 3.0.4506.2152; .NET CLR
3.5.30729)"
74.125.126.82 - - [20/Jun/2012:20:15:30 +0200] "GET /favicon.ico HTTP/1.1" 404 449 "-" "Mozilla/4.0
(compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR
3.5.21022; InfoPath.2; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"
184.82.92.239 - - [20/Jun/2012:21:03:44 +0200] "GET /logs/access.log HTTP/1.1" 200 2519 "http://isrolab.com/"
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.1; SV1) ; .NET CLR 3.5.30729)"
173.236.21.106 - - [20/Jun/2012:21:16:22 +0200] "GET /robots.txt HTTP/1.0" 404 488 "-" "Mozilla/5.0
(compatible; MJ12bot/v1.4.3; http://www.majestic12.co.uk/bot.php?+)"
173.236.21.106 - - [20/Jun/2012:21:16:23 +0200] "GET / HTTP/1.0" 200 621 "-" "Mozilla/5.0 (compatible;
MJ12bot/v1.4.3; http://www.majestic12.co.uk/bot.php?+)"
213.186.122.2 - - [20/Jun/2012:21:27:53 +0200] "GET /logs/?C=D;O=D HTTP/1.1" 200 658 "-" "Mozilla/5.0
(compatible; AhrefsBot/3.0; +http://ahrefs.com/robot/)"
66.249.72.65 - - [20/Jun/2012:21:28:00 +0200] "GET /robots.txt HTTP/1.1" 404 508 "-" "Mozilla/5.0 (compatible;
Googlebot/2.1; +http://www.google.com/bot.html)"
66.249.72.65 - - [20/Jun/2012:21:28:00 +0200] "GET /logs/ HTTP/1.1" 200 723 "-" "Mozilla/5.0 (compatible;
Googlebot/2.1; +http://www.google.com/bot.html)"
123.125.71.44 - - [20/Jun/2012:21:38:57 +0200] "GET / HTTP/1.1" 200 913 "-" "Mozilla/5.0 (compatible;
Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"
220.181.108.88 - - [20/Jun/2012:21:39:48 +0200] "GET / HTTP/1.1" 200 913 "-" "Mozilla/5.0 (compatible;
Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"
178.154.210.252 - - [20/Jun/2012:21:45:12 +0200] "GET /logs/ HTTP/1.1" 200 728 "-" "Mozilla/5.0 (compatible;
YandexBot/3.0; +http://yandex.com/bots)"
139.18.2.209 - - [20/Jun/2012:22:31:43 +0200] "GET / HTTP/1.1" 200 912 "-" "findlinks/2.6 (+http://
wortschatz.uni-leipzig.de/findlinks/)"
24. Eu não preciso disso, já tenho o
Analytics em todas as páginas.
Algum desenvolvedor
31. #!/bin/bash
[~/Apache] $ wc -l access.log
65063 access.log
[~/Apache] $ grep "HTTP/1.1" access.log | wc -l
52129
[~/Apache] $ grep "HTTP/1.0" access.log | wc -l
13007
32. #!/bin/bash
[~/Apache] $ wc -l access.log
65063 access.log
[~/Apache] $ grep "HTTP/1.1" access.log | wc -l
52129
[~/Apache] $ grep "HTTP/1.0" access.log | wc -l
13007
[~/Apache] $ grep -v "HTTP/1.1" access.log | grep -v "HTTP/1.0"
114.66.65.89 - - [24/Dec/2012:07:46:27 +0100] "GET /logs/
access.log vxc2xa4Nxd41.0" 200 1963700 "http://
www.isrolab.com/" "Mozilla/5.0 (Windows NT 6.1; rv:2.0b7pre)
Gecko/20100921 Firefox/4.0b7pre"
33. #!/bin/bash
[~/Apache] $ wc -l access.log
65063 access.log
[~/Apache] $ grep "HTTP/1.1" access.log | wc -l
52129
[~/Apache] $ grep "HTTP/1.0" access.log | wc -l
13007
[~/Apache] $ grep -v "HTTP/1.1" access.log | grep -v "HTTP/1.0"
114.66.65.89 - - [24/Dec/2012:07:46:27 +0100] "GET /logs/
access.log vxc2xa4Nxd41.0" 200 1963700 "http://
www.isrolab.com/" "Mozilla/5.0 (Windows NT 6.1; rv:2.0b7pre)
Gecko/20100921 Firefox/4.0b7pre"
39. #!/bin/bash
[~/Apache]$ head -n 1 access.log
1.202.218.8 - - [20/Jun/2012:19:05:12 +0200] "GET /robots.txt
HTTP/1.0" 404 492 "-" ""Mozilla/5.0"
[~/Apache]$ head -n 1 access.log | awk '{print $1}'
1.202.218.8
40. #!/bin/bash
[~/Apache]$ head -n 1 access.log
1.202.218.8 - - [20/Jun/2012:19:05:12 +0200] "GET /robots.txt
HTTP/1.0" 404 492 "-" ""Mozilla/5.0"
[~/Apache]$ head -n 1 access.log | awk '{print $1}'
1.202.218.8
[~/Apache]$ awk '{print $1}' access.log | head -n 10
1.202.218.8
208.115.113.91
123.125.71.20
220.181.108.101
123.125.68.79
178.154.210.252
74.125.126.102
74.125.126.103
74.125.126.93
74.125.126.82
43. #!/bin/bash
[~/Apache]$ awk '{print $1}' access.log | head -n 5
1.202.218.8
208.115.113.91
123.125.71.20
220.181.108.101
123.125.68.79
[~/Apache]$ awk '{print $1}' access.log | head -n 5 | sort
1.202.218.8
123.125.68.79
123.125.71.20
208.115.113.91
220.181.108.101
46. #!/bin/bash
[~/Apache]$ awk '{print $1}' *.log | sort | uniq | wc -l
7967
[~/Apache]$ awk '{print $1}' *.log | sort | uniq | head -n 10
1.0.250.121
1.179.147.2
1.2.209.130
1.2.215.151
1.2.216.110
1.2.217.90
1.202.218.13
1.202.218.14
1.202.218.15
1.202.218.21
47. Quais os IPs que mais acessaram
o access.log dele?
Já que sabemos que não fomos os únicos.
49. #!/bin/bash
[~/Apache]$ for ip in `awk '{print $1}' *.log | sort | uniq`; do
> count=`grep “$ip” access.log | grep 'access.log' | wc -l`;
> echo "$count $ip" >> ip-safadenhos.txt;
> done;
54. #!/bin/bash
[~/Apache]$ sort -nr ip-safadenhos.txt | head -n 10
246 88.250.57.232
184 216.151.130.179
121 88.190.16.36
90 199.59.56.24
84 80.93.217.38
73 216.152.251.7
71 89.233.105.125
68 120.196.161.251
68 120.196.161.251
58 190.254.21.236
56. Pegue já seu outro exemplo!
!g filetype:log error.log E_ERROR
58. LC_Page_Admin.php(69)] from 126.29.228.69
login_id = ()[acf83d9069c4c9036fa852909503b631]
2013/01/30 00:49:03 [/hiroshima-gift.co.jp/html/admin/index.php] Fatal error(E_ERROR): Call to a member
function doAction() on a non-object on [/home/bravecreate/www/hiroshima-gift.co.jp/data/class/pages/admin/
LC_Page_Admin.php(69)] from 126.29.228.69
login_id = ()[acf83d9069c4c9036fa852909503b631]
2013/01/30 00:50:38 [/hiroshima-gift.co.jp/html/admin/index.php] Fatal error(E_ERROR): Call to a member
function doAction() on a non-object on [/home/bravecreate/www/hiroshima-gift.co.jp/data/class/pages/admin/
LC_Page_Admin.php(69)] from 126.29.228.69
login_id = ()[acf83d9069c4c9036fa852909503b631]
2013/01/30 00:50:59 [/hiroshima-gift.co.jp/html/admin/index.php] Fatal error(E_ERROR): Call to a member
function doAction() on a non-object on [/home/bravecreate/www/hiroshima-gift.co.jp/data/class/pages/admin/
LC_Page_Admin.php(69)] from 126.29.228.69
login_id = ()[acf83d9069c4c9036fa852909503b631]
2013/04/02 14:09:39 [/hiroshima-gift.co.jp/html/index.php] Fatal error(E_USER_ERROR):
DB処çê †ãÅ §ã‚¨ãƒ©ãƒ¼ãÅ Œç™ºç”ŸãÅ —ãÅ ¾ãÅ —ãÅ Ÿã€‚
SQL: [SET SESSION storage_engine = InnoDB]
PlaceHolder: [array (
)]
MDB2 Error: insufficient permissions
_doQuery: [Error message: Could not select the database: bravecreate_nagasakiya_ec]
[Last executed query: SET SESSION storage_engine = InnoDB]
[Native code: 1044]
[Native message: Access denied for user 'bravecreate'@'%' to database 'bravecreate_nagasakiya_ec']
on [/home/bravecreate/www/hiroshima-gift.co.jp/data/class/SC_Query.php(1008)] from 66.249.74.233
customer_id =
/home/bravecreate/www/hiroshima-gift.co.jp/html/index.php(32): LC_Page_Index_Ex->init
/home/bravecreate/www/hiroshima-gift.co.jp/data/class_extends/page_extends/LC_Page_Index_Ex.php(47):
LC_Page_Index->init
/home/bravecreate/www/hiroshima-gift.co.jp/data/class/pages/LC_Page_Index.php(45): LC_Page->init
/home/bravecreate/www/hiroshima-gift.co.jp/data/class/pages/LC_Page.php(97): SC_Helper_PageLayout-
>sfGetPageLayout
/home/bravecreate/www/hiroshima-gift.co.jp/data/class/helper/SC_Helper_PageLayout.php(54):
SC_Helper_PageLayout->getPageProperties
/home/bravecreate/www/hiroshima-gift.co.jp/data/class/helper/SC_Helper_PageLayout.php(112):
SC_Query::getSingletonInstance
/home/bravecreate/www/hiroshima-gift.co.jp/data/class/SC_Query.php(104): SC_Query->__construct
/home/bravecreate/www/hiroshima-gift.co.jp/data/class/SC_Query.php(88): SC_DB_DBFactory_MYSQL->initObjQuery
/home/bravecreate/www/hiroshima-gift.co.jp/data/class/db/dbfactory/SC_DB_DBFactory_MYSQL.php(323): SC_Query-
>exec
/home/bravecreate/www/hiroshima-gift.co.jp/data/class/SC_Query.php(231): SC_Query->query
/home/bravecreate/www/hiroshima-gift.co.jp/data/class/SC_Query.php(814): SC_Query->execute
/home/bravecreate/www/hiroshima-gift.co.jp/data/class/SC_Query.php(971): SC_Query->error
60. #!/bin/bash
[~/PHP]$ awk '/(E_[A-Z])/ {print $5}' error.log | sort | uniq -c
24 error(E_ERROR):
15 error(E_USER_ERROR):
[~/PHP]$ awk -F: '/E_ERROR/ {print $4}' error.log | sort | uniq
Call to a member function doAction() on a non-object on [/home/
bravecreate/www/hiroshima-gift.co.jp/data/class/
SC_View.php(137)]
Call to a member function doAction() on a non-object on [/home/
bravecreate/www/hiroshima-gift.co.jp/data/class/
SC_View.php(137)]
Call to a member function doAction() on a non-object on [/home/
bravecreate/www/hiroshima-gift.co.jp/data/class/pages/admin/
LC_Page_Admin.php(69)]
77. 1 <?php
2 ini_set('display_errors', 1);
3 error_reporting(E_ALL);
4
5 if ($_POST['user']) {
6 // ...
7 }
8 /**
9 * Output:
10 *
11 * PHP Notice: Undefined index: user in notices.php on line 5
12 */
79. 1 <?php
2 ini_set('display_errors', 1);
3 error_reporting(E_ALL);
4
5 echo date('l').PHP_EOL;
6
7 date_default_timezone_set('America/Sao_Paulo');
8
9 echo date('l').PHP_EOL;
10
11 /**
12 * Output:
13 *
14 * PHP Warning: date(): It is not safe to rely on the system's
15 * timezone settings. You are *required* to use the date.timezone
16 * setting or the date_default_timezone_set() function.
17 * In case you used any of those methods and you are still getting
18 * this warning, you most likely misspelled the timezone identifier.
19 * We selected the timezone 'UTC' for now, but please set date.timezone
20 * to select your timezone. in date.php on line 5
21 *
22 * Saturday
23 * Saturday
24 */
80. 1 <?php
2 ini_set('display_errors', 1);
3 error_reporting(E_ALL);
4
5 include 'nao-existe.php';
6
7 /**
8 * Output:
9 *
10 * PHP Warning: include(nao-existe.php): failed to open stream:
11 * No such file or directory in warning.php on line 5
12 */
81. 1 <?php
2 ini_set('display_errors', 1);
3 error_reporting(E_ALL);
4
5 require 'nao-existe.php';
6 /**
7 * Output:
8 *
9 * PHP Warning: require(nao-existe.php): failed to open stream:
10 * No such file or directory in warning.php on line 5
11 *
12 * Fatal error: require(): Failed opening required
13 * 'nao-existe.php' in error.php on line 5
14 */
84. 1 <?php
2 date_default_timezone_set('America/Sao_Paulo');
3 error_reporting(-1);
4 ini_set('log_errors', 1);
5 ini_set('error_log', 'duh.log');
6
7 define('APP_ENV', getenv('APP_ENV') ?: 'dev');
8 switch (APP_ENV) {
9 case 'live':
10 ini_set('display_errors', 0);
11 break;
12 default:
13 ini_set('display_errors', 1);
14 break;
15 }
16
17 if (false === extension_loaded('xdebug')) {
18 trigger_error('Conhece o xDebug?', X_USER_NOTICE);
19 }
20
21 if (false === version_compare($current=PHP_VERSION, $required='6.4.0', '>=')) {
22 $msg = sprintf('Versão mínima do PHP requerida %s. (%s)', $required, $current);
23 trigger_error($msg, E_USER_ERROR);
24 unset($required, $current);
25 }
26
27 if (false === file_exists($autoload = 'vendor/autoload.php')) {
28 trigger_error('Por favor, rode a instale com `make install`.', E_USER_ERROR);
29 }
30
86. 1 <?php
2 ini_set('display_errors', 0);
3 ini_set('log_errors', 1);
4 error_reporting(-1);
5
6 error_log('É nóis na fita!');
7 error_log('Não me deixa cair no SPAM!', 1, 'a@a.com');
87. 1 <?php
2 ini_set('display_errors', 0);
3 ini_set('log_errors', 1);
4 error_reporting(-1);
5
6 error_log('É nóis na fita!');
7 error_log('Não me deixa cair no SPAM!', 1, 'a@a.com');
90. 1 <?php
2
3 namespace Math;
4
5 class Operation
6 {
7 public static function sum()
8 {
9 $args = func_get_args();
10 $result = 0;
11 foreach ($args as $arg) {
12 if (false == is_int($arg)) {
13 $msg = 'Somente inteiros permitidos';
14 throw new InvalidArgumentException($msg);
15 }
16 $result += (integer) $arg;
17 }
18
19 return $result;
20 }
21 }
22
23 echo Operation::sum(1,2,3,5.0);
92. 1 <?php
2
3 namespace Math;
4
5 require 'math.php'; // use autoload, por favor!
6
7 use InvalidArgumentException;
8 use Exception;
9
10 class Grades
11 {
12 public static function average($prova1, $prova2, $prova3)
13 {
14 try {
15 $total = Operation::sum($prova1, $prova2, $prova3);
16 } catch (InvalidArgumentException $e) {
17 $msg = 'Alguma nota esta errada.';
18 throw new InvalidArgumentException($msg, null, $e);
19 } catch (Exception $e) {
20 $msg = 'Calcular media de notas.';
21 throw new RuntimeException($msg, null, $e);
22 }
23 }
24 }
25
26 echo Grades::average(10, 10, 9.8);
100. Falhando miseravelmente com PHP
Expostos pra todos os desenvolvedores (e administradores)
envolvidos na manutenção do sistema, não para usuários.
Muito menos para toda internet.