G109B
Posts: 21
Joined: Thu Sep 12, 2013 9:57 am

PHP gives segmentation fault on simple fopen call in Stretch

Thu Nov 16, 2017 12:38 pm

I have a php script running from an apache2 web page under Stretch where

$myfile = fopen("log","w");

causes a segmentation fault.

This code runs without problem on Wheezy, is there something I am missing ?

User avatar
DougieLawson
Posts: 30450
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: PHP gives segmentation fault on simple fopen call in Stretch

Thu Nov 16, 2017 2:13 pm

Why not use the php logging function http://php.net/manual/en/function.error-log.php that will get written to /var/log/apache2/error.log (unless you change the logging file in /etc/php/7.0/apache2/php.ini).
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

G109B
Posts: 21
Joined: Thu Sep 12, 2013 9:57 am

Re: PHP gives segmentation fault on simple fopen call in Stretch

Thu Nov 16, 2017 2:27 pm

DougieLawson wrote:
Thu Nov 16, 2017 2:13 pm
Why not use the php logging function http://php.net/manual/en/function.error-log.php that will get written to /var/log/apache2/error.log (unless you change the logging file in /etc/php/7.0/apache2/php.ini).
Yes Dougie, this is exactly where I have found the message "Segmentation Fault".
Otherwise you are left non-the-wiser if you only look at the resulting blank web page.

User avatar
DougieLawson
Posts: 30450
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: PHP gives segmentation fault on simple fopen call in Stretch

Thu Nov 16, 2017 2:44 pm

G109B wrote:
Thu Nov 16, 2017 12:38 pm

Code: Select all

$myfile = fopen("log","w");
That's not the right way to log stuff. You got lucky that it worked with php5 on Wheezy.

The way to log stuff from your PHP program is

Code: Select all

error_log("stuff to log to /var/log/apache2/error.log", 0);
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

G109B
Posts: 21
Joined: Thu Sep 12, 2013 9:57 am

Re: PHP gives segmentation fault on simple fopen call in Stretch

Thu Nov 16, 2017 7:18 pm

DougieLawson wrote:
Thu Nov 16, 2017 2:44 pm
G109B wrote:
Thu Nov 16, 2017 12:38 pm

Code: Select all

$myfile = fopen("log","w");
That's not the right way to log stuff. You got lucky that it worked with php5 on Wheezy.

The way to log stuff from your PHP program is

Code: Select all

error_log("stuff to log to /var/log/apache2/error.log", 0);
Er, I think we are losing the plot here. My code was an example of an fopen call which didn't return, so calling error_log was not an option because it had core-dumped by then.

apache kindly left the message in apache2/error.log.

Return to “Advanced users”

Who is online

Users browsing this forum: No registered users and 7 guests