----- Original Message ----- 
From: "Bob"

<snip>

Hi Rob,
Wow, I wasn't expecting you to go to so much trouble, and it's much 
appreciated. There's certainly a lot for me to learn from this, from file 
handling to the way you've organised it. I'm still looking at it in 
amazement!

It works a treat and the layout and use of functions is great, making it 
easier to understand. Also, the http-equiv="refresh" is a neat trick for 
testing it.

I'm slowly realizing not to load a file or array with the data, and work 
directly on the files. It's finally sunk in.

It's not normally the done thing to give someone the complete code, but it 
would have taken a boat load of explaining on how to do it (well in my case, 
grin!).

This line threw me for I while:
$trash = fgets($log_file);
as $trash isn't used anywhere.
But, then I realised this is how you were finding the record line ending, 
which moves the file pointer to it. That's a really cool way of doing it!

I can see now why I couldn't get flock to work correctly, as I'd got it all 
wrong.
I noticed you didn't use flock($handle, LOCK_UN), so is this not needed in 
this case?
I'm still trying to understand the use of a reject.loc ?

$sleep = rand(1, 10000);
$time .= $sleep;
usleep($sleep);
I haven't work out why the random sleep yet?
I think you maybe doing something crafty that I'm missing?

Many thanks for this, Bob E.

------------------------------------

Hi Bob,

I didn't use flock($handle, LOCK_UN) as this automatically happens when the 
script thread ends. However in some cases it may improve access for other 
scripts.

I wrote the script so that other scripts can access the files as well if 
they first check and lock the lock file.

I haven't used flock before, normally I just create a lock file and check 
for its existence before accessing other files then unlinking it when 
finished. The problem with this is that if a script terminated half way 
through and doesn't unlink the lock file then there is a permanent lock. One 
solution with smaller scripts that run very quickly is to watch the lock 
file for a while longer then the scripts take to run and then access the 
files as normal.

I read somewhere that flock has issues on some platforms and has to open the 
file as write or append so I decided on a separate lock file. The log file 
is opened in read mode.

Also fclose has to be done before renaming files and fclose also unlocks a 
locked file.

The random sleep is from the php.net website. I expect that it is because 
some scripts can end up synchronised so a random delay will break 
synchronism.

Reading the script again I cab see two possible issues that you may want to 
check -

1)
function file_lock($lock_filename)
  {
  if(!($handle = file_open($lock_filename, 'w')))
    {
    return FALSE;
    }

Will opening an existing file in write mode fopen($filename, 'w') release 
any previous locks on the file ??

2)
function file_passthrough($source_handle, $destination_handle)
  {
  while(!feof($source_handle))
    {
    $buffer = fread($source_handle, 4096);
    fwrite($destination_handle, $buffer);
    }
  }

I should have explained that I am somewhat of a newbe to php!
In some other languages the above will write to a RAM buffer and the buffer 
will only be written to the file system when the file stream is closed.

Does php have a way to flush a steam buffer to the file system ?

I will look.

Rob. 


------------------------------------

Please remember to write your response BELOW the previous text. 

Community email addresses:
  Post message: php-list@yahoogroups.com
  Subscribe:    [EMAIL PROTECTED]
  Unsubscribe:  [EMAIL PROTECTED]
  List owner:   [EMAIL PROTECTED]

Shortcut URL to this page:
  http://groups.yahoo.com/group/php-listYahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-list/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/php-list/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Reply via email to