dqdpz60048 2015-05-12 22:55
浏览 221
已采纳

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!

  • 写回答

2条回答 默认 最新

  • douju9847 2015-05-13 00:22
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?