Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

ldap_free_result($result);
?>


boolean ldap_unbind(integer link)


The ldap_unbind function is an alias for ldap_close.


Semaphores


PHP offers an extension for using System V semaphores. If your operating system
supports this feature, you may add this extension to your installation of PHP. At the time
of this writing, only the Solaris, Linux, and AIX operating systems were known to
support semaphores.


Semaphores are a way to control a resource so that it is used by a single entity at once,
and they were inspired by the flags used to communicate between ships. The idea to use
an integer counter to ensure single control of a resource was described first by Edsger
Dijkstra in the early 1960s for use in operating systems.


A complete tutorial on semaphores is beyond the scope of this text. Semaphores are a
standard topic for college computer science courses, and you will find adequate
descriptions in books about operating systems. The Webopedia's page
<http://webopedia. internet.com/TERM/s/semaphore.html> is
unfortunately brief at the time of this writing. The whatis.com Web site
http://www.whatis.com/ references Unix Network Programming by W. Richard
Stevens, which was published by Prentice Hall. The second edition was published in
1997 as two volumes. You can find out more about it on the Prentice Hall Professional
Technical Reference Web site http://www.phptr.
com/ptrbooks/ptr_013490012X.html
.


Keep in mind that these PHP functions are wrappers for System V semaphore functions.
Understanding them well may aid you in using the PHP functions. If you are interested in
finding out exactly how PHP interacts with System V semaphores, I recommend reading
the source code, particularly the sysvsem.c file. Tom May's comments are very clear.


boolean sem_acquire(integer identifier)


The sem_acquire function attempts to acquire a semaphore you've identified with the
sem_get function. The function will block until the semaphore is acquired. Note that it
is possible to wait forever while attempting to acquire a semaphore. One way is if a script
acquires a semaphore to its limit and then tries to acquire it another time. In this case the
semaphore can never decrement.

Free download pdf