开发者

PHP/Perl filesize function not working on new server

I have a problem with a function that doesn't work as expected since I have moved my site from a shared hosting to a VPS (both have the same Linux OS, php version 5.2.9 and Perl version 5.8.8).

When my script store a remote file into a local directory, I run a simple php script at regular intervals (5 seconds) using XMLHttpRequest, this php script execute a Perl script that return the current file size (bytes already downloaded).

Here is the php code:

<?php
if (isset($_GET['file'])) {
    clearstatcache();
    $file = $_GET['file'];
    exec("/usr/bin/perl /home/xxxxxx/public_html/cgi-bin/filesize.pl $file", $output);
    //print_r($output);
    if (!empty($output) || $output[0] != "") {
        $currentSize = $output[0];
        file_put_contents('progress.txt', $currentSize);
    } else {
        ...
        ...
    }
}
?>

Here is the Perl code

#!/usr/bin/perl
$filename = $ARGV[0];
$filepath = '/home/xxxxxx/public_html/tmp_dir/'.$filename.'.flv';
$filesize = -s $filepath;
print $filesize;

When I was running these scripts on the shared server, I had no problem and could see the download progress, but now, the file size is only printed when开发者_JS百科 the remote file has been fully downloaded and I can't see the progress.

I think I need to change something in the php settings but I'm not sure and I don't know what needs to be changed.

OK, I'm sorry/stupid, the filesize() function works fine, thank you all guys.


If you need the file size, you could also just call the filesize function from PHP, and avoid having to use perl altogether.


The problem is probably caused by a different file location. Are you positive that the file '/home/xxxxxx/public_html/tmp_dir/'.$filename.'.flv' exists? You could test it with:

if (-e '/home/xxxxxx/public_html/tmp_dir/'.$filename.'.flv')

Remember that you could use PHP filesize() instead:

<?php
if (isset($_GET['file'])) {
    clearstatcache();
    $file = $_GET['file'];
    if (file_exists("/home/xxxxxx/public_html/tmp_dir/$file.flv") {
        $currentSize = filesize("/home/xxxxxx/public_html/tmp_dir/$file.flv");
        file_put_contents('progress.txt', $currentSize);
    } else {
        ...
        ...
    }
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜