I have 3 web services that are providing me data for my hotel booking engine. It is taking too long if I run them sequentially. Therefore I wanted to run them using threads, but I am not sure if php threading will support this and if it is safe, since all 3 processes that will handle the web service will read and write into shared tables.

Can anyone advise me on how should I proceed?


The problem your describing is complicated. Using your approach, you are going to run into problems with reading and writing data to the database. I know your question wasn't about the validity of your solution, but I feel it is unnecessarily complicated. Could you elaborate a bit on why your solution is necessary for solving this problem?

Here is an example of the kind of problems you will run into: https://stackoverflow.com/questions/2199559/what-are-concurrency-conflicts

I think a simpler approach should be explored. I suggest making one service call to retrieve and another to save all the information. This is the preferred way to have clients and servers communicate because it minimizes problems such as the one you are describing.

Implementing the solution will require the following:

  1. Write a Retrieve web service to call from your page
  2. Retrieve web service will make 1 call to the database to retrieve all your data
  3. Write a Save web service to save information
  4. Save web service will make 1 call to the database to save all your data

I don't know PHP, so I can't write any code or refer you to any PHP specific resources to help.

  • This is actually a common problem when working on property rental portals in my experience. Property managers use a variety of data providers to get their property info into various portals. A good portal will want to pull from a number of providers and aggregate all of this into a local database. The information also changes fairly often, since rates are seasonal and availability calendars change all the time. We used to handle this by pulling updates from each provider once a night, and pulling a last-minute update for an individual property when a customer was ready to book. – Hey Nov 25 '14 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.