Code: Select all
<?php
// capture output for writing to file
ob_start();
include("html/property.htm");
// copy buffer to string
$browser_output = ob_get_contents();
// silently clear buffer
ob_end_clean();
// write file
$filename = WRITE_PATH . $cid . '/prop/' . htmlspecialchars(strtolower(str_replace($search, $replace, $property))) . '.htm';
echo $filename . '<br>'; #DEBUG
$fp = fopen($filename, "wb");
fputs($fp, $browser_output);
fclose($fp);
// WRITE_PATH is a constant - ftp://username:password@www.whoownsscot ... age_cache/
?>Everything works fine on my local server (apache, Win, php 4.2) but it behaves VERY strangely when I tested it live (Linux, php 4.1.2).
------------------------------------
(1) Sometimes no files are created at all and I get "success" (?!) error messages for each row in the loop:
Warning: fopen("ftp://...@www.whoownsscotland.org.uk/pa ... uccoth.htm", "wb") - Success in /www.whoownsscotland.org.uk/page_cache/cache_builder.php on line 269
Warning: Supplied argument is not a valid File-Handle resource in /www.whoownsscotland.org.uk/page_cache/cache_builder.php on line 270
Warning: Supplied argument is not a valid File-Handle resource in /www.whoownsscotland.org.uk/page_cache/cache_builder.php on line 271
(fopen is on line 269, fputs on 270, and fclose on 271)
--------------------------------
(2) Other times, some files will be written - but always just FOUR files out of the several hundred that should be created.
As the script runs through the loop, first off I get these error messages as it tries to write over files which already exist:
Warning: File already exists in /www.whoownsscotland.org.uk/page_cache/cache_builder.php
Warning: fopen("ftp://...@www.whoownsscotland.org.uk/pa ... irsaid.htm", "wb") - File exists in /www.whoownsscotland.org.uk/page_cache/cache_builder.php
Warning: Supplied argument is not a valid File-Handle resource in /www.whoownsscotland.org.uk/page_cache/cache_builder.php
Next, the script will write just four files before spewing out more error messages for the rest of the loop (same error as in (1) above):
Warning: fopen("ftp://...@www.whoownsscotland.org.uk/pa ... uccoth.htm", "wb") - Success in /www.whoownsscotland.org.uk/page_cache/cache_builder.php
Warning: Supplied argument is not a valid File-Handle resource in /www.whoownsscotland.org.uk/page_cache/cache_builder.php
Warning: Supplied argument is not a valid File-Handle resource in /www.whoownsscotland.org.uk/page_cache/cache_builder.php
-------------------------
Wierd, eh?
It's not a timeout problem (only takes about 12s to get through the loop).
If it failed consistently I'd be happier because then I could try to isolate the problem. The erratic behaviour - sometimes churning out "success" errors, and sometimes writing four files (why just four?) with different error messages before and after the four files are written - has me stumped.
If it's at all relevant, CHMOD'ing folders on the site also produces strange results: after changing settings the folder just refuses to open in my ftp program giving a 550 message. Can't delete it either - 550 again. Same deal even when I change back to the original settings - so I'm stuck with a bunch of dud folders!
Php is usually well-behaved and logical but I think my host has installed a "giggling madman" version.
The script works perfectly locally: maybe I should abandon the website and just invite everyone who wants to view it round to my home