$reset_Array=(); // I forgot to put the keyword "array"
Correct way should be
$rest_Array= array();
Why does Apache crash when I try to execute wrong code.
What is happening internally?
I don't think that Apache crashes. What happens is your PHP execution aborts, resulting in you seeing 500 Internal server error. This is due to the fact that syntax
$reset_Array=();
is invalid in PHP. PHP is trying to parse this line and encounters an error. It returns this error and the execution aborts. Try the following: put in a new file test.php the following:
<?php
$reset_Array=();
?>
And execute this with a command-line interpreter with -l parameter (lint - syntax checking):
$ php -l test.php
You will get the following error:
$ php -l publish/test.php
PHP Parse error: parse error in test.php on line 3
Errors parsing test.php
Once PHP encounters this error, it cannot continue executing the script, because it cannot parse it. Hence you receive an error when you try executing it under Apache.
P.S. The above commands are shown from unix/linux shell. If you are running under windows, then your prompt may be something like C:\Documents > instead of $.
Apache isn't crashing. It's just no errors are being displayed.
You could look at the errors in the error_log file, which resides in the same directory as your php script.
What you could do is look in your php.ini file for the uncommented line error_reporting = foo. Change that foo to E_ALL.
Then it should show the errors, instead of just simply so-called 'crashing'.
Related
While debugging PHP with xdebug, sometimes a script will suddenly restart at the beginning of index.php. Why is this?
Edit:
I also sporadically get errors. For example:
Fatal error: Call to a member function getEvents() on a non-object in ...
But I never get these errors when I'm not debugging.
I'm on a server with apache2.4, php7.2, mysql (on linuxmint)..
I enabled the proxy_fcgi module and php-fpm to enable the http2 protocol.
Everything is working fine, but I am kind of bugged by the fact that now, php parsing errors are just outputted on the apache error log (of the virtual host).
For example if I omit a semicolon at the end of a line with a define() function somewhere in the php file before a new define().., I get that error in the log:
[proxy_fcgi:error] [pid 16261:tid 140594642073344] [client 127.0.0.1:36542] AH01071: Got error 'PHP message: PHP Parse error: syntax error, unexpected 'define' (T_STRING) in /var/vhosts/localhost/index.php on line 12\n'.
Which is fine, but in the browser I get no error at all, I just have a 500 Internal server status blank page.
Before setting up the proxy I used to get the php parsing errors displayed in the browser, which is much easier to debug, it's annoying to keep the error log open to check whatever small parsing error I might have.
Please don't try to get me to install an IDE editor, or use "php -l filename.php". I simply want the errors back in the browser output.
I have all the settings properly defined in all php.ini files, display_errors On, error_reporting E_ALL. It's all working fine since it's outputted to the error log :)
What I'd like to know is how to setup fpm/fcgi to stop outputting a 500 error page in the browser and actually re-forward the php errors straight in the browser as a 200 page, how it was before installing this proxy..
In the specific example, I would like to have "PHP Parse error: syntax error, unexpected 'define' (T_STRING) in /var/vhosts/localhost/index.php on line 12\n'" on the browser output again :)
I'm working in a team on a e-shop website.
Recently, we've passed on Debian Jessie and from php5.4 to 5.6
Since then, we have multiple bug with require and require_once
Here's a file that raise an ERROR 500
<?php
require('/data/vhosts/mycompany.com/public_html/mp/../includes/functions/marketplace_tools.php');
//print_r(get_included_files());
require_once('/data/vhosts/mycompany.com/public_html/mp/../includes/functions/marketplace_tools.php');
echo 'pouet';
?>
The error.log say this :
PHP Fatal error: Cannot redeclare match_marketplace_products() in Cannot redeclare match_marketplace_products() on line 1
The filepath is good.
Marketplace_tools.php don't have require/include in
Marketplace_tools.php is just a bunch of function we use
If I run this file in command line, it works well
If I uncomment the print_r, it does not raise ERROR 500
This bug randomly appear and disapear
Cannot redeclare match_marketplace_products()
This error message tells you that there is a function name (match_marketplace_products) in the file you're including that already exists in the current PHP program.
You're using require_once(), but check that you haven't pulled in the same file elsewhere using require() (or include()).
Also check that the function name match_marketplace_products is only defined in this one file -- if it's defined in another file that is also included, then this will cause this error.
I have a very simple test.php file:
<?php
echo 'Hello World';
Then I run it from Mac Shell: php test.php
But it does not echo anything. Looks like it's blocked for some reason, like this:
If I use invalid syntax in the file, for example:
<?php
invalid syntax
Then I can see the error output:
PHP Parse error: syntax error, unexpected 'syntax' (T_STRING) in .../test.php on line 3
Parse error: syntax error, unexpected 'syntax' (T_STRING) in .../test.php on line 3
What's wrong with it?
FYI:
Running php -i can print php.ini info
Running echo 'test' can print 'test'
Turning my comments into an answer as requested:
Here are two possible reasons why php command doesn't work as expected:
Maybe it is aliased (try which php or prepend a backslash (\) to the command)
You mentioned that you had a directory named php on your working directory. Well, zsh has a feature called AUTO_CD that may have interfered in this case. Basically AUTO_CD allows you to switch directories without typing cd and can be disabled by adding unsetopt autocd to zshrc file.
I am getting the below error while triggering the file with crone jobs, while it doesn't show any error with manual triggering. Please help whats the logic behind this error. Thanks
Fatal error: Call to a member function find() on a non-object in /home/afghannewscom/public_html/auto/MainProject.php on line 35
Look at the file MainProject.php on line 35 (in editor) and see whats the problem.
the variable $OuterLink is not an object. you may have a look at its definition line.
I also had a similar issue with cronjobs (PHP errors in cronjobs only, running file via browser was fine). The error was caused by incorrect server configuration (it was a shared server, so I couldn't change it). In my case, the fix was pretty easy - I changed cronjob from "php -q /some_file.php" to "curl http://somedomain.com/some_file.php" (you can also use lynx or wget command instead of curl)