0

I used cURL to authenticate first then login via POST to a cms.

Then another POST again to ask the cms to generate a new code number (eg voucher code) and grab the csv from url that contain about 70 lines per page.

I can explode each line and get the last line for the new code number that is generated before.

My question is if many requests are created by many customers, is it possible to accidentally reading the same voucher code? Although cURL get the csv file pretty fast, should I make sure that a request must be completed first before another? like a sql transaction.

Though I read somewhere php do not run in parallel, since I am a beginner in all these and someone asked me if my script can cause that for multiple requests. THanks in advance.

4

1 回答 1

0

The only way you will get the same voucher code is if the remote server generates the same code twice. You are correct in saying php do not run in parallel but concurrency has nothing to do with your specific case, there is no way the two HTTP response get mixed up with each other because they are sent back to you in different TCP streams. The underlying TCP/IP stack of the OS will prevent collisions.

Regardless of this, you should be able to check for collisions after you have received the data. For example, if you are inserting it into an SQL database, you can create a unique index on the field that holds the code, and the database will prevent you from inserting duplicated rows.

As a side note, you say you can explode each line which is true, but you may wish to have a look at fgetcsv() and str_getcsv(), which will parse the line for you and take into account escape sequences and all sorts of edge-cases that you code will not account for. If you want to perform multiple cURL requests at once, you may also want to have a look at curl_multi_exec(), which will allow you to execute several requests at once and speed up the execution of your script.

于 2012-04-07T16:44:04.847 回答