Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

PHP copy() and a 4GB limit

Posted on 2008-10-13
12
1,481 Views
Last Modified: 2013-12-06
On a FreeBSD 6.2 system, my PHP scripts are encountering a 4GB filesize limit when using copy(). The copy process simply fails when 4 gigabytes have been transferred.

The attempted transfer is from a local file to a local file, and the filesystem is UFS (which has a 1TB filesize limit).

I have been unable to find any documentation regarding such a limit in PHP or FreeBSD. Can anyone provide a work-around for copying large files within PHP? Shelling out and using system commands is a possibility, but I would prefer to stay in PHP if possible.

PHP version is 5.1.6 with the Suhosin patch.
0
Comment
Question by:glcummins
12 Comments
 
LVL 9

Expert Comment

by:chingmd
ID: 22703445
I'm no php expert, but reading your question, made me think that the limit is PHP itself.    That being the case, I would split the file into managable sizes, and unsplit (if needed) in the destination location.

0
 
LVL 24

Author Comment

by:glcummins
ID: 22703488
I agree that this sounds like a PHP limit. However, I have been unable to find anything in the PHP documentation that would indicate such a limit.

Unfortunately, splitting the file is not an option in this case. A confirmation from someone that they have encountered a similar issue would be enough to determine that this is a system (rather than a user) error.
0
 
LVL 3

Expert Comment

by:smueller72
ID: 22703503
You can always use shell_exec to run shell commands with php
http://us3.php.net/shell_exec

There will be no limit as you are basically running a shell command, and it uses php.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 24

Author Comment

by:glcummins
ID: 22703537
Shelling out is a possibility, but I would prefer to stay in PHP if I can.

If no other solution presents itself, however, this will be the only option I can see.
0
 
LVL 3

Expert Comment

by:smueller72
ID: 22704934
can you do a df -h in bash and post the results here? im wondering if your /tmp dir only has 4gb available.
0
 
LVL 3

Expert Comment

by:smueller72
ID: 22704951
also, if you are using a fat32 filesystem, it does not support files larger than 4gb.
0
 
LVL 24

Author Comment

by:glcummins
ID: 22705031
I am using ufs which should have a 1TB filesize limit. Here is the output of df:

Filesystem     Size    Used   Avail Capacity  Mounted on
/dev/ad4s1a   190M     57M   117M    33%     /
devfs              1.0K    1.0K       0B   100%    /dev
/dev/ad4s4d     74G     42G     26G     62%    /usr
/dev/ad4s3d     69G     56M     64G      0%    /var
/dev/ad5s1     144G     35G     97G     27%    /var/db/mysql

If the file copy process was dependent on the /tmp directory it would fail much sooner than 4GB, I think, since the / directory has only 190M in total size.
0
 
LVL 3

Expert Comment

by:smueller72
ID: 22705397
have you tried a similar transfer with something large, but not as large as 4gb? (ex. 1gb).
0
 
LVL 24

Author Comment

by:glcummins
ID: 22705567
Yes, I have tested with a range of file sizes, and anything up to 4GB works.
0
 
LVL 2

Accepted Solution

by:
michel-angelo earned 500 total points
ID: 22705699
If this is a PHP limitation and you would like to stay within the script (No exec""), could you use fopen and fread to copy the file in chuncks?
0
 
LVL 24

Author Comment

by:glcummins
ID: 22705753
@michel-angelo:

That's an idea. I'll give it a try and report back.
0
 
LVL 24

Author Comment

by:glcummins
ID: 22976200
I apologize for the delay in closing this question. Thank you for your assistance.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question