Fopen error

software development

#1

Hi, I’ve written a routine which basically creates some RSS and then dumps it to a XML file. When I run my code, I get an error when I call ‘fopen’ saying that the file is too large, yet I haven’t dumped the XML by then and in any case, the RSS has only ten items (of plain text) and is nowhere near the 2GB PHP 32 bit limit.

function write($contents, $file_name)
{
$DEBUG = false;
$succeeded = false;

// Delete old file
$this->delete($file_name);

if ($DEBUG == true) { echo “fopening “.$file_name.”
”; }

// Create handle to new file
if (!$fh = fopen($file_name, ‘w’)) // error happens on this line
{
if ($DEBUG == true) { echo “fopen “.$file_name.” failed.
”; }
$succeeded = false; // failed
}
else // Only write the file if the handle is ok
{
if ($DEBUG == true) { echo “fopen “.$file_name.” succeeded.
”; }

// Write new file
if (!fwrite($fh, $contents))
{
if ($DEBUG == true) { echo “fwrite “.$file_name.” failed.
”; }
$succeeded = false; // failed
}
else
{
if ($DEBUG == true) { echo “fwrite “.$file_name.” succeeded.
”; }
$succeeded = true; // success
}

fclose($fh);
}

The actual error message is:
Warning: fopen(/home/bestevecom/feeds/Comments.xml) [function.fopen]: failed to open stream: File too large in /home/.pipkin/bestevecom/CRSS.php on line 136

I’ve no idea why I’d get this ‘File too large’ error. Just wondered if anybody could help shed some light…


#2

btw, I get exactly the same error when using file_put_contents


#3

Check the error log for the domain at /home/user/logs/…

Maximum Cash Discount on any plan with MAXCASH

How To Install PHP.INI / ionCube on DreamHost


#4

thanks, I think I’ve found the problem now. There were over 100,000 files in the directory where I was creating the new file and I must have hit some kind of upper limit. I deleted some files from this directory and the code started working again… (I’m well inside my disk allowance so I’m not sure where this limitation is coming from)