flock Warning

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
lazersam
Forum Contributor
Posts: 105
Joined: Sat Nov 15, 2003 4:07 am
Location: Hertfordshire, UK

flock Warning

Post 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?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

last I saw, flock() didn't work for remote/networked files..
Post Reply