I'm new in PHP. I run file.php on my PC with Firefox but I don't know how see error. What I can add to see it, is possible if I have this file on pc and not on server?
Maybe this:
error_reporting(E_ALL);
ini_set('display_errors', 1);
or it works only on Apache?
I tried nothing because I don't know how solve it.
This my file.php
<?php
include('wrapper.php');
$apikey = "xxx7d7391d1e68e9680e6";
voxmail_init($apikey);
voxmail_user_subscribe(array('mail' => 'xxxxx#gmail.com','privacy' => 1));
?>
This file used api newsletter service (the code - for assistance of service - is ok) and voxmail_user_subscribe register the email address at newsletter. wrapper.php is file in same folder of file.php for use API of this service.
In this wrapper.php is there include other file xmlrpc.inc (also in same folder)
Now when I run file.php in my browser the only thing that I see is this:
**'xxxx#gmail.com','privacy' => 1));?>**
but the assistant servec tried my code and works... he ask me to show error log, but I don't know where is this log.
Those directives can be set in lots of different places, as explained at Runtime Configuration. You need to be aware of the different syntaxes:
If you set them from PHP code, you have to compose valid PHP code, e.g.:
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
If you set it in PHP configuration files (php.ini or .user.ini) you have to use valid *.ini syntax:
error_reporting = E_ALL
display_errors = On
If you set it in Apache configuration files (httpd.conf or .htaccess) you have to use valid apache syntax:
php_value error_reporting E_ALL
php_flag display_errors On
It's worth noting that errors that prevent PHP code from running (such as parse errors) cannot be set from within PHP code.
My advice is to configure your local system-wide file for development (display all errors, log none) and configure your project for dual configuration (display in development, log in production).
Answer to updated question:
can't see any obvious reason why your code should trigger errors and notices. Are you sure it does? Have you tried with something that should trigger one such as 1/0;?
If you can see PHP code in the browser, your code is not running at all.
Example
error_log("You messed up!", 3, "/var/tmp/my-errors.log");
You can use
error_log — Send an error message somewhere
Related
I have an Apache2 web server with PHP 5.5 installed.
My default PHP settings is display_error = 0 (I don't need globally displayed errors) but I need it on in specific PHP files.
I tried with:
error_reporting(E_ALL);
ini_set("display_errors", 1);
and it's not working.
Can someone tell me how can I make it show errors in specific PHP files?
i am try to force some error writing some no syntax logic and not showing error...
To show parse errors in PHP you have to put this on your php.ini
display_errors = on
My advice is to avoid displaying errors on production servers but log them all. So you can later inspect and fix bugs from yoursite-error.log file.
You should be concerned if your applications has warnings, errors etc. IMHO it is a bad idea to focus your attention only on few files instead of them all.
Although display_errors may be set at runtime (with ini_set()), it won't have any effect if the script has fatal errors. This is because the desired runtime action does not get executed.
I'm trying to see what error PHP is producing. So I've changed the value of dispaly_errors to ON in the etc/php5/apache2/php.ini file.
The file doesn't display anything and I don't see any error on the webpages.
Am I missing any thing?
First, you have to make sure that this is your correct ini file. Usually the file you have used is the correct one. If not sure, you can create a simple PHP program to call the phpinfo() function and check this out.
Next, you have to restart Apache. Without a restart your settings don't take effect.
Another thing... This file can be a little misleading because there are so many comments in it. The actual line to change is way down. On my setup (LAMP/Ubuntu) the setting is on line 538.
Open php.ini file from your php folder, remove semicolon from all error reporting like
;error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT, ;display_errors=On etc, at last, restart your server, you will find all error messages.
Another way for showing error, you can write these codes in your script -
echo '<pre>';
error_reporting(E_ALL);
ini_set('display_errors', 1);
In addition to enabling display_errors, you may also need to set the error reporting level. if you are expecting errors with a script that is redirecting, be sure to turn off the redirection or you may never see them.
I am having two servers, both are hosted on hostgator. On one server (which is my own), my php code works as expected, while on another (which is of my client), the code doesn't work properly. Now my server generates error_log file, so it's easier to debug. But I can't find the same error_log file on my client's server.
Is there anything I can do to generate error_log file. I've already seen answers on other posts and checked the settings in php.ini file.
Your other server may have error log turned off, so you can do the following.
error_reporting(E_ALL); //to set the level of errors to log, E_ALL sets all warning, info , error
ini_set("log_errors", true);
ini_set("error_log", "/your_error_path/file.log"); //send error log to log file specified here.
Add the above code to your file and then execute in the other server.
First of all, check the software version. Then, you could try diffing the two files (php.ini) .
I have a WAMP 2.2 server running on a Windows 7 box and cannot get PHP error logging working at all.
The file is always blank even after I explicitly trigger USER_ERROR errors, or cause normal ERROR errors.
I'm including the error relevant sections of the php.ini file - hopefully you can find something:
error_reporting = E_ALL
error_log = "c:/wamp32/logs/php_error.log" ;(UNCOMMENTED BY ME)
log_errors = On
display_errors = On
The line ; log_errors is just a comment for the following block, for the purpose of showing you what the settings are in dev vs production. You uncommented four lines which aren't meant to control anything, and I'm surprised your Apache service doesn't have problems starting up because of it.
What you need to do is look for the line:
log_errors = Off
And change the value to On
That said, once you restart the Apache service, the settings should take effect. However, I was unable to get WampServer to properly log php errors despite these settings. Apache will not start up when I specify the error_log parameter.
For me it turned out to be a permissions error. I ended up giving EVERYONE full control of the error log file and it seemed to fix my issue. Best of luck.
Did you try adding these lines to your php file?
ini_set("display_errors", "1");
ini_set("log_errors", "1");
ini_set("error_log", "/wamp64/logs/php_error.log");
I want PHP to display parse errors on screen. What I get instead is a blank page. Nothing gets written to server's error log file.
My setup: PHP5.2.9/IIS 6 (not Apache!).
My PHP.INI:
error_reporting=E_STRICT
display_errors = On
display_startup_errors = On
log_errors = On
error_log = "C:\Program Files\Zend\ZendServer\logs\php_error.log"
How do I get parse or fatal errors to be either logged or shown on screen?
Thanks,
Temuri
UPDATE: After playing with different switches it looks to be an IIS specific problem. ANY IDEAS FOLKS?
Setting error level in php file itself does not resolve the problem here because the file itself cannot be parsed !!
You need to change error_reporting line in your php.ini as follows:
error_reporting = E_ALL
BTW: There are some examples in php.ini file about what to do to display which type of error messages.
Good luck,
mcemoz
Apache doesn't always like to report parsing errors either. From the command line, run
php -l <file>
The -l switch tells PHP to check file syntax. See the man page.
E_STRICT is not included in E_ALL (until PHP 6). If you want to keep getting E_STRICT
In php.ini:
error_reporting = E_ALL | E_STRICT
At runtime:
error_reporting( E_ALL | E_STRICT );
You'll need to set the error reporting level (and display_errors) in php.ini to see syntax errors. If PHP encounters a syntax error, the runtime doesn't get executed, so setting at runtime won't work. (See the display_errors link.)
You can verify the script syntax with this command in terminal:
php -l path/to/file.php
Personally, I added this line to my ~/.bash_profile file so I can easily run php -l on all files in the current working directory:
phpl() { for i in *.php; do php -l $i; done }
If you're really hardcore, you can even run your app from the command line. You'll have a much better chance of seeing compile-time errors, and it's just kinda cool.
You can use the $argv variable to get the first argument, $argv[1], then use that as the request.
<?php
// show those errors!
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
// simulate a web server request
$request = '/' . isset($argv[1]) ? ltrim($argv[1], '/') : '/';
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'] = $request;
Then you can run your script via command line. This would be the equivalent of visiting:
your-webapp.com/request/uri/here
php /path/to/script.php request/uri/here
Here is a more comprehensive example for running CodeIgniter via command line. It should work for many other frameworks too: http://phpstarter.net/2008/12/run-codeigniter-from-the-command-line-ssh/
As Rasmus Lerdorf suggests, always use error_reporting(-1) on development server.
Re: Blank screen of php death death, I discovered that setting
php_value error_reporting "E_ALL" or
php_value error_reporting 8192
in .htaccess on my Windows 7, Wampserver w/ apache 2.2.4 and php 5.3.13 are sure ways to get the blank php error screen -- today, June 3, 2014. These htaccess lines DO set the desires value in phpinfo(), but the display of the errors happens only when the line is commented out (not used) in htaccess.
BUT... the next minute I discover that
php_value error_reporting 8191
DOES set the phpinfo() value AND also allows display of the error messages to the browser! D'oh! It must be an integer and also apparently a particular or valid integer, and not just a large enough integer!
If you're using Zend Framework (v1) and you're using the Autoloader, the following code will prevent parse errors from being displayed:
self::$Autoloader->suppressNotFoundWarnings(true);
See the following answer for more details:
Display php errors when using Zend framework
Try this.
error_reporting(E_ALL);
ini_set("display_errors", 1);