0

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 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.

4
  • Why do you call a Perl script to just get the filesize? PHP can do this fine for you, you don't need the exec there. Commented May 16, 2011 at 6:54
  • @ Konerak - How do you do it? Commented May 16, 2011 at 6:59
  • @ Mario - This is not an upload, I download the remote file using cURL. Commented May 16, 2011 at 7:01
  • I believe you need to show us the script downloading the file and also the script reading progress.txt. What is the output of print_r($output)? Commented May 16, 2011 at 7:38

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

I have already tested this function, it only print the size when the file is fully downloaded, so I cant' see the progress, but thanks any way...
1

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 {
        ...
        ...
    }
}
?>

2 Comments

Yes I'm sure that the file exists because when it's fully downloaded I convert it into a different format. I'm pretty sure that I have already tested filesize(), it only print the size when the file is fully downloaded, and this is not what I need to see the progress.
@Maxime I'm sorry this wasn't the problem. I'll comment on your question, since I'll remove this answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.