Forum Moderators: coopster

Message Too Old, No Replies

copy() on files bigger than 4GB

         

typek

5:20 am on Apr 23, 2020 (gmt 0)

5+ Year Member



Is there a filesize limit on the copy() function?

running the copy command on various files, it seems the limit is around 4GB.

No matter what size the file is, it returns true.
- If the file is <4GB, it seems the full file has been copied over just fine.
- If the file is >4GB, it seems to have only copied over a portion of the file. Some files are 3.5GB, some are 1GB, some are only a couple hundred MBs big

Also, if I try and recopy the same exact file over again, the exact result happens. So if the first time, it was a 5GB file, and it resulted in a 1GB file, the re-copy will result in 1GB (to the exact byte).

I have tried using stream_copy_to_stream() . Same result, even the same exact file as if I tried to re-copy() the file.

Searching around, can't seem to find anything in regards to a file size limit. It is not timing out (execution time limit has been changed, but doesn't even come close to hitting it, as with the result with a couple hundred MBs only takes a few seconds to complete).

I was able to get the copy to complete by running an exec command (exec(xcopy SRC DEST /Y)).

Setup:
WampServer 3.0.6 64-bit (running PHP 7.0.10)
Windows 64 64bit
Source Drive is NTFS
Destination Drive is NTFS, external drive (but doesn't matter based on tests)

Any help would be appreciated.

tangor

7:42 am on Apr 23, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



@typek ... Welcome to Webmasterworld!

Which version of Windows?

Are you writing to USB for the destination, or is this internal to your server... or is it a network drive, details, please.

typek

7:55 am on Apr 23, 2020 (gmt 0)

5+ Year Member



Sorry, mistyped in the OP.

Windows 10.

Source is on an internal drive. I am mainly wanting to copy to an external drive via USB3. But the issue happens no matter the destination, whether another internal drive in the computer, the same internal drive as source, or a USB. Haven't tried on a network drive. Even tried copying it to/from a SSD. Same thing

brotherhood of LAN

8:05 am on Apr 23, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you run this from the command line, do you get 8 back?
php -r "echo PHP_INT_SIZE;"

typek

8:15 am on Apr 23, 2020 (gmt 0)

5+ Year Member



If I run it via cmdline via the php5.6.25 folder, it outputs 4.

If I run it in php7.0.10 folder, it outputs 8

But I am not running the script via command line? Script is running php7.0.10 and output of echo PHP_INT_SIZE; in the script is 8.

I initially thought that it was an issue with the int size, but isn't that an issue with 2GB files and over?

phranque

9:15 am on Apr 23, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], typek!

have you looked for clues in the server error log file?
perhaps you have run into a memory limit or similar problem.

JorgeV

12:18 pm on Apr 23, 2020 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



Hello,

PHP_INT_SIZE is the size of int used in PHP "language", but, internal functions might use different types.

4 years ago, there was this comment :

Copying large files under Windows 8.1, from one NTFS filesystem to another NTFS filesystem, results in only the first 4 GiB copied and the rest of the file is ignored.

So, if you think to have files larger than 4 GiB, instead of doing:
copy($source,$destination);
it is much better to do something like:
exec("xcopy $source $destination");
[php.net...]

lammert

4:16 pm on Apr 23, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



PHP internally uses the C compiler type size_t to determine the number of bytes to copy between files. The size of this type may be different from the size of an integer in the PHP engine, depending on the compiler and settings used when building PHP.

typek

5:05 pm on Apr 23, 2020 (gmt 0)

5+ Year Member



@phranque yeah, checked. Nothing in the logs at all.

@JorgeV Iammert brotherhoodoflan Yeah, that probably sounds like what it is. That comment is what got me to use the exec command to do the copy in my script. I just initially turned it down at the time because I would have thought the issue would show up at 2GB files and larger, not 4GB. Also, the comment says it would copy the first 4 GiB and ignore the rest. But with my various files I was testing, it would get some arbitrary random size of the file up to 4GiB (was getting anywhere from 92MB to 3.8GB). So I guess I figured it might be something else

Thanks everyone