TheTechGuy
TheTechGuy

Reputation: 17384

How does php script executes

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.

Upvotes: 2

Views: 267

Answers (2)

Silvertiger
Silvertiger

Reputation: 1680

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.

Upvotes: 3

ceejayoz
ceejayoz

Reputation: 180137

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.

Upvotes: 1

Related Questions