Page 1 of 1

flock Warning

Posted: Thu Oct 27, 2005 3:54 am
by lazersam
I have a script that reads a text file. The flock is producing an error
Warning: flock(): 252 bytes of buffered data lost during conversion to FILE*! in /home/*****/public_html/Link_Manager/admin.php on line 8
The script is basic....

Code: Select all

//get file.....
			$filename = "http://www.****.com/files/Real_Estate.txt";
			$filesize = strlen(file_get_contents("http://www.****.com/files/Real_Estate.txt"));
			$fp = fopen ("$filename", "r");
			
			flock($fp, LOCK_EX);//Lock the file
			
			
#===============================================================================================	
		//Loop through	
		while (!feof ($fp)) {
						
				$link = fgets( $fp, $filesize );
				
				//code here		
						}
#===============================================================================================	
		flock($fp, LOCK_UN);// Release the lock
		fclose($fp);
Any ideas... I am running PHP 4.3.11?

Posted: Thu Oct 27, 2005 4:02 am
by Jenk
Hi, sorry, but I can't help directly with the flock problem, but you could avoid using it altogether just by using file_get_contents() as you already have done.

What are you attempting to achieve?

You can explode() to seperate lines:

Code: Select all

<?php

$links = explode("\n", file_get_contents('http://www.****.com/files/Real_Estate.txt'));

foreach ($links as $link) {

    // code

}

?>

EDIT: nvm, just noticed you have set the buffer to the full file size, but is food for thought maybe :p

Posted: Thu Oct 27, 2005 10:30 am
by feyd
last I saw, flock() didn't work for remote/networked files..