tags:

views:

58

answers:

3

I'm having trouble opening MySQL's slow query log with PHP. I'm writing a debugger and trying to tap into the log file but it's giving me a permission denied message.

Code:

$log = file_get_contents('/var/log/mysql/mysql-slow.log');

Response (error):

Warning: file_get_contents(...): failed to open stream: Permission denied ...

I can cat the file just fine from a terminal. I've chmoded the log file to 0777 with the same result. Is this operation not allowed while MySQL is running? Are there ways around this?

PHP5.2.10, Ubuntu 9.10, MySQL 5.1.37

+1  A: 

At a guess I'd say the user that php is running as isn't the same or isn't in the same group as the owner of the log file.

You could try changing the owner of the log file, but that might stop mysql from having permission to write to it.

Can you read the file with fopen?

adam
With 777 permissions, the file owner and PHP user/group shouldn't matter.
Wim
Correct, but there are obvious security implications
adam
+1  A: 

did you tryed popen?

$fp=popen("cat /var/log/mysql/mysql-slow.log","r");
while (!feof($fp)) {
    $buffer = fgets($fp, 4096);
    $croninf .= '<tr><td>' . $buffer . '</td></tr>' . "\n";
} 
streetparade
+1  A: 

Also make sure the directory /var/log/mysql has at least execute permission (711) for your webserver's user, I believe it is 700 by default in Ubuntu.

Wim