fopen()有效,dio_open()不行吗?

Seeing some issues running fopen() when dio_open() is working just fine. Here's a test script I wrote to check the issue as it was appearing in a new installation I'm trying to get working.

<?php
        echo "Current User: " . get_current_user() . "<br/>";
        echo "UID: " . getmyuid() . "<br/>";
        echo "GID: " . getmygid() . "<br/>";
        echo "<br/>";
        $foTest = fopen("test.txt","r");
        echo fread($foTest,4);

        $fd = dio_open('test.txt', O_RDONLY);
        $read = dio_read($fd);
        echo $read;
        $file = dio_open('test.txt', O_WRONLY | O_CREAT);
?>

The script outputs the following:

Current User: infinitywhack UID: 1004 GID: 1002

test Warning: dio_open(): cannot open file test.txt with flags 0 and permissions 0: No such file or directory in /var/www/infinity.whacknet.com/public_html/test.php on line 9

Warning: dio_read() expects parameter 1 to be resource, boolean given in /var/www/infinity.whacknet.com/public_html/test.php on line 10

Warning: dio_open(): cannot open file test.txt with flags 65 and permissions 0: Permission denied in /var/www/infinity.whacknet.com/public_html/test.php on line 12

This shows the user and group (infinitywhack:www) which is correct. The "test" output here is the content of the test.txt file, that is the code that is running with fopen(). The errors are only given by dio functions.

Here are the permissions for both files:

[root@death public_html]# ls -la test.*
-r-xr-xr-x. 1 infinitywhack www 342 May 12 23:36 test.php
-rwxrwxrwx. 1 infinitywhack www   5 May 12 23:06 test.txt

I've been scratching my head all night on this one, there's very little documentation on anything dio from what I have found. Very little saying what is needed here. The only thing I could think of was suExec but there aren't any directives in use that would cause this, although surely those same directives would fail for fopen as well if that were the case?

Any help here would be much appreciated!

I think STLMikey & Ahmet are on the right track.

Try dio_open(__DIR__ . DIRECTORY_SEPARATOR . 'test.txt', ...)

In this source code at least, dio_open makes no attempt to construct an absolute path. The filename parameter is passed to the operating system unchanged.

The No such file or directory & Permission denied errors are coming from the OS, not the dio library. So it seems likely your server is looking for test.txt in the wrong place.

firsty make sure your file is exist. Also your php file permissions should be 0777 to create file and you can add a folder to set permission "777" automaticly by this command

$folder=mkdir( "yourdirname", 0777);

And than you should try to understand the problem

 $file="test.txt";
    //maybe your server cannot find the root
    // if it does not solve the problem write root file command
// $file=dirname(__FILE__).DIRECTORY_SEPARATOR."test.txt";
    if (file_exists($file)) {
       //its ok try to continue
    } else {
        echo "the text file is not exits !";
    }