Jump to content

Semaphores & Syncronization


FredAt

Recommended Posts

I am planning to use PHP with SQLite to do so custom logging for one of my websites.  The reccomendation from the folks on the SQLiute forums is that instead of writing directly to the DB I should cache the writes and do them in a batch since this will improve site access.

 

OK - know how I would do that in Windows in a traditional programming language such as C++ or Delphi but I am fairly new to PHP so I need to ensure that I am still barking up the right tree.

 

I can do either write all my SQL to a temporary text file or to a memory map using sh_mop and then run another PHP script to clean up the cache every few seconds/minutes.  In both cases, I am suspect I need to do some work to ensure syncronization of reads/writes to my memory map/text file.  In Windows I would simply use Windows Event objects.  From what I have read thus far PHP does not offer Events.  I could use the PHP semaphore functions but this is where I start getting confused.

 

There is information on the net that suggests that sem_acquire will simply return false if the semaphore is in use by another process.  But then there is also information that suggests that it will block.  In the former case I would have to run a loop along with a usleep statement before writing my SQL or abandoning the effort. If sem_acquire actually blocks things get messier.  I would rather abandon an occassional log entry rather than have the process lock because it cannot access a semaphore that has been blocked by another process that failed.

 

I would be much obliged to anyone who could clarify these issues.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.