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) .
Related
I have a php script that reads a csv file that contains URLs, follows the URLs, parses them and save some data into a database. The csv is around 1000 lines. However, my php script seems to stop after parsing some URLs (between 2 and 15 - never less, never more, but always different) neither showing any error in the browser nor writing it to php_errors.php.
I have also placed enabled php server logging via .htaccess:
# enable PHP error logging
php_flag log_errors on
php_value error_log "home/user/public_html/path/php_errors.log"
Also did I set the logging parameters in the php script with:
error_reporting(E_ALL);
ini_set('display_errors', 1);
I have no idea how to catch the reason why the script breaks. It really works perfect until it stops.
Before adding this question I run into another question on stackoverflow and addressed all the resolutions.
I set display_errors = on in php.ini.
My script has no syntax errors and it parses well to a point.
Try this:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
How do I get PHP errors to display?
you can also check the /var/log/apache/ folder and try to locate error.log - it should contain error message independent of error show settings
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
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.
How would I go about changing where PHP logs it's syntax errors? I've got multiple people working on the same server, and I want to be able to send my own logs to a custom file so that I'm not looking at every one else's errors.
I can do this:
error_reporting(E_ALL);
ini_set('display_errors','On');
ini_set('error_log','path/to/mylogfile.log');
And that works for some errors, but for actual syntax errors, the logs are still being sent to the master /var/log/httpd/error_log. How do I make the syntax errors get sent to my custom log file?
Since the file cannot be correctly parsed, the ini_set function is not executed either and neither is the new error log set. You need to set php_value error_log /path/to/myfile.log in an .htaccess file or the global server config (I'm assuming that you're using Apache).
Given that syntax errors prevent PHP from running you will not be able to set log paths via PHP. It's a chicken before the egg situation.
Alternatives would be:
Change the error log at the webserver level
Enable output of error messages to the browser
I'd suggest the latter.
I'm using ssh2_scp_send to send one file from server1 to server2.
It works almost 80% of the times, but sometimes fails and I can't find any log message and i don't know why!
the command only return one bool value saying if it was sucessfull.
ssh2_scp_send
Where can I find some log message or any of you had one similar problem?
Thanks,
Pedro
#pedro
The path to the PHP error log is defined with "error_log" in PHP.ini. In your PHP script you should display all errors during development.
error_reporting(E_ALL);
You can also choose to show errors in the PHP output.
ini_set('display_errors', 1);
There is an alternative shown on:
http://php.oregonstate.edu/manual/en/function.ssh2-scp-send.php#82927
That may give you more flexible error handling.
PHP SSH2 is a probably a wrapper around the "libssh2", so if you are looking for logs then check your syslog config file, if ssh logging is not enabled in there then ssh logs the activity in apache log files. Logs are generally stored in /var/log
One good debugging technique would be to enable logging in php.ini
log_errors = On
error_log = /path/to/logfile.log
ssh2_scp_send fails for me if the file size is more then 2 GiB, it uploads 2 GiB and then stops.