2

I have two similar questions

  1. How does php script executes. For example I have a file that is being called with certain parameters. Let's say the script first start processing the request, then connect to a database where it inserts values into a table then displays or logs a report in text file. Lets say the PHP file was in the middle of inserting data into the database and another request comes. Will it process this second request?

  2. Talking bout PayPal API and esp IPN Listner, PayPal advices to keep the Listener minimal. So lets say my listener just got a request of payment notification with about 20 parameters. Now I am going to save these into the database but at the same time want to get free quick so I can catch other requests as well. What should be my logic here? Use CURL or something similar to post the request to another page where data is inserted into the table? That will keep my primary listener less loaded and quick. Is this the correct approach? Or I should do data insertion in the primary listener.

Note: I have checked How exactly is a PHP script executed? and the answer their has a one hour lecture on PHP internal. Not a clear cut answer.

Community
  • 1
  • 1
TheTechGuy
  • 16,560
  • 16
  • 115
  • 136
  • Question #1: Each http request that executes PHP runs as a separate, totally independent thread, so your first script won't stop executing when a second request is received... they'll __both__ run to completion. – Mark Baker Jan 17 '12 at 19:31
  • so the first request is in the middle, the second one arrives. They both will be completed separate? It is not that since the script was busy in the first script, it is going to miss the second one? – TheTechGuy Jan 17 '12 at 19:38
  • 2
    Unless you're locking resources (such as session files) that are __deliberately__ shared between the two processes, they will both run completely independently. – Mark Baker Jan 17 '12 at 19:39

2 Answers2

3

the PHP script will function as it should regardless of how many times it is called. if the php is being executed and is requested again, it will create a new "instance" of this php that run along side the other already running copy so you should not receive any interruption.

IPN listener is an example of this type of transaction. Each url request from paypal will be handled by a seperate copy of the php script and process completely without interruption.

Silvertiger
  • 1,680
  • 2
  • 19
  • 32
1

How does php script executes. For example I have a file that is being called with certain parameters. Let's say the script first start processing the request, then connect to a database where it inserts values into a table then displays or logs a report in text file. Lets say the PHP file was in the middle of inserting data into the database and another request comes. Will it process this second request?

A separate instance of PHP will be used.

Talking bout PayPal API and esp IPN Listner, PayPal advices to keep the Listener minimal. So lets say my listener just got a request of payment notification with about 20 parameters. Now I am going to save these into the database but at the same time want to get free quick so I can catch other requests as well. What should be my logic here? Use CURL or something similar to post the request to another page where data is inserted into the table? That will keep my primary listener less loaded and quick. Is this the correct aproach? Or I should do data insertion in the primary listener.

No, cURL is blocking, so that'd just make things worse. Just do it in the main PHP file that's being accessed - if 20 people hit it all at once, your web server should have no trouble keeping them separate.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368