By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,723 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,723 IT Pros & Developers. It's quick & easy.

using fopen() in write mode is failing

P: n/a
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}
}

on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"

Am I missing something?
Jun 2 '08 #1
Share this Question
Share on Google+
20 Replies


P: n/a
On May 30, 9:08*pm, cscor...@gmail.com wrote:
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
* * * * global $file;
* * * * if (file_exists($name) && file_exists($file)) {
* * * * * * * * if(($fp = fopen($file,"wb"))){
* * * * * * * * * * * * $lastmod = filemtime($name);
* * * * * * * * * * * * if(!(fwrite($fp, $lastmod))){
* * * * * * * * * * * * * * * * echo "cannot update time";
* * * * * * * * * * * * }
* * * * * * * * }
* * * * * * * * else{
* * * * * * * * * * * * echo "$file cannot be opened. \n";
* * * * * * * * }
* * * * }
* * * * else{
* * * * * * * * echo "$name or $file not found.";
* * * * }

}

on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"

Am I missing something?
Is error reporting on? If it is then PHP will echo out its own error
message in addition to yours. Did you originally create the file
you're trying to write to or was it created via a PHP script? If the
former is the case then it will have you as the owner. PHP runs as the
webserver's user (something like www or apache or nobody, assuming
you're using PHP in a webserver environment). This will mean a
permission denied error occurs when you try to open the file. Try
setting the file to 666 chmod, or chown it to the Apache process's
user.
Jun 2 '08 #2

P: n/a
On May 30, 3:13 pm, Gordon <gordon.mc...@ntlworld.comwrote:
On May 30, 9:08 pm, cscor...@gmail.com wrote:
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.
PHP Version 5.2.5
Apache/2.2.8
code snip in question:
$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}
}
on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"
Am I missing something?

Is error reporting on? If it is then PHP will echo out its own error
message in addition to yours. Did you originally create the file
you're trying to write to or was it created via a PHP script? If the
former is the case then it will have you as the owner. PHP runs as the
webserver's user (something like www or apache or nobody, assuming
you're using PHP in a webserver environment). This will mean a
permission denied error occurs when you try to open the file. Try
setting the file to 666 chmod, or chown it to the Apache process's
user.
I 'touch'ed the file on the server itself, so yes its owned by my
user. I've attempted to chown+chgrp the file to apache's, but it
doesn't help at all. The file is already chmod'ed to 0766.

After turning on error reporting, it outputs this:

"Warning: fopen(time) [function.fopen]: failed to open stream:
Permission denied in /var/www/html/xmlparser.php on line 53"

with line 53 being the $fp = fopen().. line.
Jun 2 '08 #3

P: n/a
cs******@gmail.com wrote:
On May 30, 3:13 pm, Gordon <gordon.mc...@ntlworld.comwrote:
>On May 30, 9:08 pm, cscor...@gmail.com wrote:
>>For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.
PHP Version 5.2.5
Apache/2.2.8
code snip in question:
$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}
}
on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"
Am I missing something?
Is error reporting on? If it is then PHP will echo out its own error
message in addition to yours. Did you originally create the file
you're trying to write to or was it created via a PHP script? If the
former is the case then it will have you as the owner. PHP runs as the
webserver's user (something like www or apache or nobody, assuming
you're using PHP in a webserver environment). This will mean a
permission denied error occurs when you try to open the file. Try
setting the file to 666 chmod, or chown it to the Apache process's
user.

I 'touch'ed the file on the server itself, so yes its owned by my
user. I've attempted to chown+chgrp the file to apache's, but it
doesn't help at all. The file is already chmod'ed to 0766.

After turning on error reporting, it outputs this:

"Warning: fopen(time) [function.fopen]: failed to open stream:
Permission denied in /var/www/html/xmlparser.php on line 53"

with line 53 being the $fp = fopen().. line.
What's in $file at the time you try to call fopen()? And why do you
have the file set as executable by the owner?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 2 '08 #4

P: n/a
On May 30, 4:26 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
cscor...@gmail.com wrote:
On May 30, 3:13 pm, Gordon <gordon.mc...@ntlworld.comwrote:
On May 30, 9:08 pm, cscor...@gmail.com wrote:
>For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.
PHP Version 5.2.5
Apache/2.2.8
code snip in question:
$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}
}
on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"
Am I missing something?
Is error reporting on? If it is then PHP will echo out its own error
message in addition to yours. Did you originally create the file
you're trying to write to or was it created via a PHP script? If the
former is the case then it will have you as the owner. PHP runs as the
webserver's user (something like www or apache or nobody, assuming
you're using PHP in a webserver environment). This will mean a
permission denied error occurs when you try to open the file. Try
setting the file to 666 chmod, or chown it to the Apache process's
user.
I 'touch'ed the file on the server itself, so yes its owned by my
user. I've attempted to chown+chgrp the file to apache's, but it
doesn't help at all. The file is already chmod'ed to 0766.
After turning on error reporting, it outputs this:
"Warning: fopen(time) [function.fopen]: failed to open stream:
Permission denied in /var/www/html/xmlparser.php on line 53"
with line 53 being the $fp = fopen().. line.

What's in $file at the time you try to call fopen()? And why do you
have the file set as executable by the owner?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
The file named "time" is (sans quotations of course) in $file. The
time file itself is blank.

It was just set for rwx when I touched the file, so i just kept it and
added write permissions to the file for other users. I've changed it
to 0666 but it doesn't seem to affect anything.
Jun 2 '08 #5

P: n/a
On Sat, 31 May 2008 00:54:42 +0200, <cs******@gmail.comwrote:
On May 30, 4:26 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>cscor...@gmail.com wrote:
On May 30, 3:13 pm, Gordon <gordon.mc...@ntlworld.comwrote:
On May 30, 9:08 pm, cscor...@gmail.com wrote:
>>For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.
PHP Version 5.2.5
Apache/2.2.8
code snip in question:
$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}
}
on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"
Am I missing something?
Is error reporting on? If it is then PHP will echo out its own error
message in addition to yours. Did you originally create the file
you're trying to write to or was it created via a PHP script? If the
former is the case then it will have you as the owner. PHP runs as
the
>webserver's user (something like www or apache or nobody, assuming
you're using PHP in a webserver environment). This will mean a
permission denied error occurs when you try to open the file. Try
setting the file to 666 chmod, or chown it to the Apache process's
user.
I 'touch'ed the file on the server itself, so yes its owned by my
user. I've attempted to chown+chgrp the file to apache's, but it
doesn't help at all. The file is already chmod'ed to 0766.
After turning on error reporting, it outputs this:
"Warning: fopen(time) [function.fopen]: failed to open stream:
Permission denied in /var/www/html/xmlparser.php on line 53"
with line 53 being the $fp = fopen().. line.

What's in $file at the time you try to call fopen()? And why do you
have the file set as executable by the owner?

The file named "time" is (sans quotations of course) in $file. The
time file itself is blank.

It was just set for rwx when I touched the file, so i just kept it and
added write permissions to the file for other users. I've changed it
to 0666 but it doesn't seem to affect anything.
What is your getcwd()? Is it what you expect / the directory 'time' should
be in?
--
Rik Wasmus
....spamrun finished
Jun 2 '08 #6

P: n/a
On May 30, 4:08 pm, cscor...@gmail.com wrote:
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}

}

on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"

Am I missing something?

A little off-topic, but your code is an example of the Arrow Anti-
Pattern:

http://c2.com/cgi/wiki?ArrowAntiPattern

http://www.codinghorror.com/blog/archives/000486.html
Jun 2 '08 #7

P: n/a
On May 30, 4:08 pm, cscor...@gmail.com wrote:
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}

}

on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"

Am I missing something?

If you chmod $file to 0777 does your script then work?
Jun 2 '08 #8

P: n/a
On May 30, 6:02 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
What is your getcwd()? Is it what you expect / the directory 'time' should
be in?
--
Rik Wasmus
...spamrun finished
Yes, it returns the expected directory. Whenever I set the fopen to
use read mode, it gets into the if body fine.

On May 30, 9:59 pm, lawrence k <lkrub...@geocities.comwrote:
A little off-topic, but your code is an example of the Arrow Anti-
Pattern:

http://c2.com/cgi/wiki?ArrowAntiPattern

http://www.codinghorror.com/blog/archives/000486.html
Ah, I have a bad habit of that. I just write out what I think and
eventually get around to cleaning things up again once it works :]

On May 30, 10:17 pm, lawrence k <lkrub...@geocities.comwrote:
If you chmod $file to 0777 does your script then work?
No. All that does is add execute permissions to the file anyway.
Jun 2 '08 #9

P: n/a
On May 30, 3:08 pm, cscor...@gmail.com wrote:
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}

}

on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"

Am I missing something?
Actually, I think it must have something to do with the way this
particular webserver is setup (be it apache/php), because it works
fine when tested on another server (not maintained by me).
Jun 2 '08 #10

P: n/a
cs******@gmail.com wrote:
On May 30, 3:08 pm, cscor...@gmail.com wrote:
>For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}

}

on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"

Am I missing something?

Actually, I think it must have something to do with the way this
particular webserver is setup (be it apache/php), because it works
fine when tested on another server (not maintained by me).

It's true. Is there any chance you've an older version of PHP installed,
some version from before the "b" flag was introduced? Have you tried:

fopen($file,"w")

just to see what would happen?
Jun 2 '08 #11

P: n/a
On May 31, 2:08 am, Lawrence Krubner <lawre...@krubner.comwrote:
cscor...@gmail.com wrote:
On May 30, 3:08 pm, cscor...@gmail.com wrote:
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.
PHP Version 5.2.5
Apache/2.2.8
code snip in question:
$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}
}
on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"
Am I missing something?
Actually, I think it must have something to do with the way this
particular webserver is setup (be it apache/php), because it works
fine when tested on another server (not maintained by me).

It's true. Is there any chance you've an older version of PHP installed,
some version from before the "b" flag was introduced? Have you tried:

fopen($file,"w")

just to see what would happen?
I've tried all modes that include writing options (r+, w+, a, etc),
and none of them seem to work. The PHP verion is 5.2.5, and reflects
that when I do phpinfo(). The server in question is Fedora9 with php/
apache installed via yum from the repos, and both have nearly default
settings.
Jun 2 '08 #12

P: n/a
On May 31, 3:59*am, lawrence k <lkrub...@geocities.comwrote:
On May 30, 4:08 pm, cscor...@gmail.com wrote:
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.
PHP Version 5.2.5
Apache/2.2.8
code snip in question:
$file = "time";
function updateParseTime($name){
* * * * global $file;
* * * * if (file_exists($name) && file_exists($file)) {
* * * * * * * * if(($fp = fopen($file,"wb"))){
* * * * * * * * * * * * $lastmod = filemtime($name);
* * * * * * * * * * * * if(!(fwrite($fp, $lastmod))){
* * * * * * * * * * * * * * * * echo "cannot update time";
* * * * * * * * * * * * }
* * * * * * * * }
* * * * * * * * else{
* * * * * * * * * * * * echo "$file cannot be opened. \n";
* * * * * * * * }
* * * * }
* * * * else{
* * * * * * * * echo "$name or $file not found.";
* * * * }
}
on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"
Am I missing something?

A little off-topic, but your code is an example of the Arrow Anti-
Pattern:

http://c2.com/cgi/wiki?ArrowAntiPattern

http://www.codinghorror.com/blog/archives/000486.html
I personally find quite a few things some programmers designate as
"anti-patterns" are really just things the particular programmer
doesn't like. For example excessive commenting is claimed to be a
code smell, but I personally would much rather maintain a piece of
code with a lot of comments than a piece of code with none. It's true
enough that comments can be used incorrectly, for example using
esoteric variable names and using comments to say what they are,
variable names should be self-descriptive. And well written code will
get its what and how across quite well, but even the best written code
can't really convey its why. That's where comments come in.

As for the whole "Arrows anti pattern", the author asserts it results
in error handler code a long way from where the error might occur.
This is also true of exceptions, where the handler doesn't even have
to be in the same module. Overuse of exceptions is a far bigger sin
in my opinion than nesting ifs. The code and its error handler are
part of the same section in the arrow approach, and you can tell what
error handle belongs to what code because it will be on the same
indentation level.

Good code should narrative, which is more true of the arrow pattern
than badly used exceptions. There is nothing wrong with the structure
of the OP's code. In fact its structure pointed to exactly where the
problem lay almost immediately and allowed me to formulate a theory
quickly, namely that the script didn't have permission to write to the
file being manipulated.

As for the OP's problem, it looks from the error message PHP emitted
that the PHP user doesn't have write permission for the file in
question. I'd suggest adjusting chown, chmod and chgrp on the file,
but it looks like you've already done all that. Another possibility
is that some other program or script has opened and flocked the file
to prevent more than one process writing to it at a time. If the
software doesn't release its lock no other application or script can
write to it even if they do have permission. If other applications
have been accessing the file in question then try checking that they
have been closed down properly. If they have and the file is still
locked then you may have to resort to a restart of your system.
Jun 2 '08 #13

P: n/a
lawrence k wrote:
On May 30, 4:08 pm, cscor...@gmail.com wrote:
>For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}

}

on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"

Am I missing something?


If you chmod $file to 0777 does your script then work?
Why would you set the 'x' bit on a non-executable file? That's just
asking for even more trouble.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 2 '08 #14

P: n/a
cs******@gmail.com wrote:
On May 30, 3:08 pm, cscor...@gmail.com wrote:
>For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}

}

on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"

Am I missing something?

Actually, I think it must have something to do with the way this
particular webserver is setup (be it apache/php), because it works
fine when tested on another server (not maintained by me).
What OS is it running on (i.e. if Linux, which distro)? It could be the
OS security isn't allowing it, despite the file flags.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 2 '08 #15

P: n/a
On Sat, 31 May 2008 14:52:04 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:
cs******@gmail.com wrote:
>On May 30, 3:08 pm, cscor...@gmail.com wrote:
>>For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}

}

on the 4th line it fails the if check ($fp = fopen..) and just
outputs "$file cannot be opened"

Am I missing something?
Actually, I think it must have something to do with the way this
particular webserver is setup (be it apache/php), because it works
fine when tested on another server (not maintained by me).

What OS is it running on (i.e. if Linux, which distro)? It could be the
OS security isn't allowing it, despite the file flags.
He just said Fedora9(PHP5.2.5 for distro).
I'd be interested in a clearstatcache();printf('%o',fileperms('time'));
output.
--
Rik Wasmus
....spamrun finished
Jun 2 '08 #16

P: n/a
Rik Wasmus wrote:
On Sat, 31 May 2008 14:52:04 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:
>cs******@gmail.com wrote:
>>On May 30, 3:08 pm, cscor...@gmail.com wrote:
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}

}

on the 4th line it fails the if check ($fp = fopen..) and just
outputs "$file cannot be opened"

Am I missing something?
Actually, I think it must have something to do with the way this
particular webserver is setup (be it apache/php), because it works
fine when tested on another server (not maintained by me).

What OS is it running on (i.e. if Linux, which distro)? It could be
the OS security isn't allowing it, despite the file flags.

He just said Fedora9(PHP5.2.5 for distro).
I'd be interested in a clearstatcache();printf('%o',fileperms('time'));
output.
Ah, I missed that, Rik - this thread is getting too long for my short
memory! :-)

I've never used Fedora9 - but I don't *think* it has additional security
features (like SE Linux), does it?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 2 '08 #17

P: n/a
On Sat, 31 May 2008 15:33:25 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:
Rik Wasmus wrote:
>On Sat, 31 May 2008 14:52:04 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:
>>cs******@gmail.com wrote:
On May 30, 3:08 pm, cscor...@gmail.com wrote:
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.
>
PHP Version 5.2.5
Apache/2.2.8
>
code snip in question:
>
$file = "time";
function updateParseTime($name){
global $file;
if (file_exists($name) && file_exists($file)) {
if(($fp = fopen($file,"wb"))){
$lastmod = filemtime($name);
if(!(fwrite($fp, $lastmod))){
echo "cannot update time";
}
}
else{
echo "$file cannot be opened. \n";
}
}
else{
echo "$name or $file not found.";
}
>
}
>
on the 4th line it fails the if check ($fp = fopen..) and just
outputs "$file cannot be opened"
>
Am I missing something?
Actually, I think it must have something to do with the way this
particular webserver is setup (be it apache/php), because it works
fine when tested on another server (not maintained by me).

What OS is it running on (i.e. if Linux, which distro)? It could be
the OS security isn't allowing it, despite the file flags.
He just said Fedora9(PHP5.2.5 for distro).
I'd be interested in a clearstatcache();printf('%o',fileperms('time'));
output.

Ah, I missed that, Rik - this thread is getting too long for my short
memory! :-)

I've never used Fedora9 - but I don't *think* it has additional security
features (like SE Linux), does it?
Erm:
"Fedora is the first mainstream operating system to provide MAC (Mandatory
Access Control) based security using ["SELinux"] enabled by default. "

So, now that you mention it, a chcon might be necessary...
--
Rik Wasmus
....spamrun finished
Jun 2 '08 #18

P: n/a
Rik Wasmus wrote:
On Sat, 31 May 2008 15:33:25 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:
>Rik Wasmus wrote:
>>On Sat, 31 May 2008 14:52:04 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:

cs******@gmail.com wrote:
On May 30, 3:08 pm, cscor...@gmail.com wrote:
>For some reason, I cannot use fopen() on the file in write mode. The
>file "time" is in the same directory as the .php file, with
>permissions set to 0766.
>>
>PHP Version 5.2.5
>Apache/2.2.8
>>
>code snip in question:
>>
>$file = "time";
>function updateParseTime($name){
> global $file;
> if (file_exists($name) && file_exists($file)) {
> if(($fp = fopen($file,"wb"))){
> $lastmod = filemtime($name);
> if(!(fwrite($fp, $lastmod))){
> echo "cannot update time";
> }
> }
> else{
> echo "$file cannot be opened. \n";
> }
> }
> else{
> echo "$name or $file not found.";
> }
>>
>}
>>
>on the 4th line it fails the if check ($fp = fopen..) and just
>outputs "$file cannot be opened"
>>
>Am I missing something?
Actually, I think it must have something to do with the way this
particular webserver is setup (be it apache/php), because it works
fine when tested on another server (not maintained by me).

What OS is it running on (i.e. if Linux, which distro)? It could be
the OS security isn't allowing it, despite the file flags.
He just said Fedora9(PHP5.2.5 for distro).
I'd be interested in a
clearstatcache();printf('%o',fileperms('time') ); output.

Ah, I missed that, Rik - this thread is getting too long for my short
memory! :-)

I've never used Fedora9 - but I don't *think* it has additional
security features (like SE Linux), does it?

Erm:
"Fedora is the first mainstream operating system to provide MAC
(Mandatory Access Control) based security using ["SELinux"] enabled by
default. "

So, now that you mention it, a chcon might be necessary...
Ah, OK. As I said I'm not familiar with it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 2 '08 #19

P: n/a
On Sat, 31 May 2008 15:55:26 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:
Rik Wasmus wrote:
>On Sat, 31 May 2008 15:33:25 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:
>>Rik Wasmus wrote:
On Sat, 31 May 2008 14:52:04 +0200, Jerry Stuckle
<js*******@attglobal.netwrote:

cs******@gmail.com wrote:
>On May 30, 3:08 pm, cscor...@gmail.com wrote:
>>For some reason, I cannot use fopen() on the file in write mode.
>>The
>>file "time" is in the same directory as the .php file, with
>>permissions set to 0766.
>>>
>>PHP Version 5.2.5
>>Apache/2.2.8
>>>
>>code snip in question:
>>>
>>$file = "time";
>>function updateParseTime($name){
>> global $file;
>> if (file_exists($name) && file_exists($file)) {
>> if(($fp = fopen($file,"wb"))){
>> $lastmod = filemtime($name);
>> if(!(fwrite($fp, $lastmod))){
>> echo "cannot update time";
>> }
>> }
>> else{
>> echo "$file cannot be opened. \n";
>> }
>> }
>> else{
>> echo "$name or $file not found.";
>> }
>>>
>>}
>>>
>>on the 4th line it fails the if check ($fp = fopen..) and just
>>outputs "$file cannot be opened"
>>>
>>Am I missing something?
> Actually, I think it must have something to do with the way this
>particular webserver is setup (be it apache/php), because it works
>fine when tested on another server (not maintained by me).
>
What OS is it running on (i.e. if Linux, which distro)? It could be
the OS security isn't allowing it, despite the file flags.
He just said Fedora9(PHP5.2.5 for distro).
I'd be interested in a
clearstatcache();printf('%o',fileperms('time')) ; output.

Ah, I missed that, Rik - this thread is getting too long for my short
memory! :-)

I've never used Fedora9 - but I don't *think* it has additional
security features (like SE Linux), does it?
Erm:
"Fedora is the first mainstream operating system to provide MAC
(Mandatory Access Control) based security using ["SELinux"] enabled by
default. "
So, now that you mention it, a chcon might be necessary...

Ah, OK. As I said I'm not familiar with it.
Haven't worked with SELinux either.. But it just might be the cause of all
this trouble.
--
Rik Wasmus
....spamrun finished
Jun 2 '08 #20

P: n/a
On May 31, 9:07 am, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
On Sat, 31 May 2008 15:55:26 +0200, Jerry Stuckle

<jstuck...@attglobal.netwrote:
Rik Wasmus wrote:
On Sat, 31 May 2008 15:33:25 +0200, Jerry Stuckle
<jstuck...@attglobal.netwrote:
>Rik Wasmus wrote:
On Sat, 31 May 2008 14:52:04 +0200, Jerry Stuckle
<jstuck...@attglobal.netwrote:
>>>cscor...@gmail.com wrote:
On May 30, 3:08 pm, cscor...@gmail.com wrote:
>For some reason, I cannot use fopen() on the file in write mode.
>The
>file "time" is in the same directory as the .php file, with
>permissions set to 0766.
>>>>>PHP Version 5.2.5
>Apache/2.2.8
>>>>>code snip in question:
>>>>>$file = "time";
>function updateParseTime($name){
> global $file;
> if (file_exists($name) && file_exists($file)) {
> if(($fp = fopen($file,"wb"))){
> $lastmod = filemtime($name);
> if(!(fwrite($fp, $lastmod))){
> echo "cannot update time";
> }
> }
> else{
> echo "$file cannot be opened. \n";
> }
> }
> else{
> echo "$name or $file not found.";
> }
>>>>>}
>>>>>on the 4th line it fails the if check ($fp = fopen..) and just
>outputs "$file cannot be opened"
>>>>>Am I missing something?
Actually, I think it must have something to do with the way this
particular webserver is setup (be it apache/php), because it works
fine when tested on another server (not maintained by me).
>>>What OS is it running on (i.e. if Linux, which distro)? It could be
the OS security isn't allowing it, despite the file flags.
He just said Fedora9(PHP5.2.5 for distro).
I'd be interested in a
clearstatcache();printf('%o',fileperms('time') ); output.
>Ah, I missed that, Rik - this thread is getting too long for my short
memory! :-)
>I've never used Fedora9 - but I don't *think* it has additional
security features (like SE Linux), does it?
Erm:
"Fedora is the first mainstream operating system to provide MAC
(Mandatory Access Control) based security using ["SELinux"] enabled by
default. "
So, now that you mention it, a chcon might be necessary...
Ah, OK. As I said I'm not familiar with it.

Haven't worked with SELinux either.. But it just might be the cause of all
this trouble.
--
Rik Wasmus
...spamrun finished
And it was. Disabled SELinux then rebooted, and now everything works
fine. I didn't even think of SELinux being a problem since I don't
recall being asked in setup/install if I wanted it enabled (which is
usually what happens)..

Thanks for the help all!
Jun 2 '08 #21

This discussion thread is closed

Replies have been disabled for this discussion.