0

I'm using php wget to download mp4 files from another server

exec("wget -P files/ $http_url");

but I didn't find any option to check if file downloaded correctly, or not yet.

I tried to get duration file using getID3(), but it always return good value, even if file not downloaded correctly

// Check file duration
$file = $getID3->analyze($filepath);
echo $file['playtime_string']; // 15:00 always good value

there is any function to check that?

Thanks

Zeta
  • 663
  • 1
  • 12
  • 27

1 Answers1

0

First off I would try https instead. If the server(s) you're connecting to happen to support it, you get around this entire issue because lost bytes are usually caused by flaky hardware or bad MTU settings on a router on their network. The http connections gracefully degrade to giving you as much of the file as it could manage, whereas https connections just plain fail when they lose bytes because you can't decrypt non-intact packets. Lazy IT people tend to get prodded to fix complete failures of https, but they get less pressure to diagnose and fix corner cases like missing bytes that only occur larger transactions over http.

If https is not available, keep reading.

An HTTP server response may include a Content-Length header indicating the number of bytes in a particular transaction. If the header is there, you should be able to see it by running wget directly, adding the -v flag. If it's not there, I believe wget will report Length: unspecified followed by the content-type header's value. If it tells you (and assuming the byte count is accurate) then you can just compare the byte count of the file you got and the one in the transaction.

If the server(s) you're contacting don't provide this header, you're left with less exact methods, like finding some player that will basically play the mp3 until it ends and then see how long it took and then compare that to the length listed in the ID3 tag (which is in the very beginning of the file). You're not going to be able to get an exact match though, because the time in the tag (if it's there) is only accurate to the second, meaning half a second could be gone from the end of the file and you wouldn't know.

LinuxDisciple
  • 2,289
  • 16
  • 19
  • Hi I'm using wget http exec("wget -P files/ $http_url"); – Zeta Apr 12 '17 at 18:58
  • thanks for detailed answer @LinuxDisciple, what if I use wget first, and after 5min, I want to check using php function? there is any possibility? – Zeta Apr 12 '17 at 20:08