Cheap Web Hosting for Developers

PHP, MySQL, Java, Unix Cheap Web Hosting

Interfacing the Network 105 Here s the hard part:We

Filed under: Web Applications Development With PHP4.0 — webmaster @ 00:34

106 Chapter 3 Application Design: A Real-Life Example Main process Input field Data exchange container (”door”) Figure 3.7 Upstream communication. The situation can be compared to a car race.The driver racing on the track is the main client and the racing team in the pit is the user input field.The driver is bound to the race he s in; he can t just leave the track and stop to see what s going on. Whenever the racing team flags him in for a pit stop, they interface to him giving him a signal to make a break after the next lap. What s being done is (leaving radio communication aside) to signal every time the driver passes the finish line.This signal works as the interface to the driver.Basically this is what we need to do,too signal to our main process.Since the main process is event-based, we frequently get the chance to take control over the application and do what we want to do.This means that we can install a handler that looks frequently for a signal from the outside.The method to periodically stop and check for incoming data is called polling and will be the preferred method for phpChat. phpIRC features idle callbacks, which get invoked every time phpIRC has nothing to do and simply waits for something to happen on the network.Tagging a handler to this event enables us to watch out for a signal. Now, how are we going to signal something? This is actually pretty easy, using one of the following methods: n Set a flag in a database. n Create a lockfile in the file system. n Use semaphores. n Set a flag in shared memory. These are basically the methods that we have with PHP to leave a message. The following sections describe each method. Pipes can t be used for interprocess communication here, because a pipe requires two processes to be running at the same time. Our situation requires interfacing one constantly running process from other, short-term processes. Note: Of course, more exotic methods are available, such as sending emails between processes.We ve seen people doing this,but we won t go into that option here,as the disadvantages should be clear to the reader. Setting a Flag in a Database Setting a flag in a database is probably the de facto standard method for PHP users: Connect to a database, leave some data in it, let it be processed further by other processes.This method is extremely easy to implement and is available on all systems, but has a disadvantage. Can you tell what the disadvantage is?

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP Web Hosting services

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.

Powered by Cheap Web Hosting