Page 2 of 2
Re: How to run second php script under the main script
Posted: Wed Sep 10, 2008 2:20 am
by girishkoshti007
The problem is that mine system is an SMS gateway of sorts. its acts like a mediator between between 2 servers. 2 companies are are forwarding a sms to me, I am then sending this sms to the server where this will be processed and they will hit me back with data. the sms's companies are trying to send me about 20sms's per minute. but the step where i hit the processing server is increasing the time execution time. so i need to put that onto a different thread so that the page where i receive the sms will execute very fast and independant of the processing server time.
i could create a cron job that executes once every second this but my server have a cron job minimum start time limit of 5 mins and the entire cycle of responding to the sms that has been received cannot take more then 10-15 seconds.
thus the need to just execute a hit to the process server on a different thread which should not affect the processing time of this thread.
I hope this all makes sense.
Re: How to run second php script under the main script
Posted: Wed Sep 10, 2008 5:07 am
by VladSun
Do you have shell access to the server?
Or even root access?
Re: How to run second php script under the main script
Posted: Wed Sep 10, 2008 5:56 am
by girishkoshti007
dont have root access. not sure about the shell but i am sure that i can get the hosting admins help us out with almost anything.
Re: How to run second php script under the main script
Posted: Wed Sep 10, 2008 6:24 am
by VladSun
So, you can write a daemon script, which will communicate with your PHP scripts (e.g. via DB) and send requests to the other server, process the answer and write it back.
Re: How to run second php script under the main script
Posted: Wed Sep 10, 2008 7:21 am
by girishkoshti007
Vlad you are a life saver. that worked perfectly. I am going try and implement this into the system, this will allow the sms people to continously hit us and there should not be a delay from the processing server since the second php page would handle it.
Re: How to run second php script under the main script
Posted: Wed Sep 10, 2008 7:28 am
by VladSun
I'm glad you are happy with it, although I'm not sure what you have done

Can you give us your solution details?
Re: How to run second php script under the main script
Posted: Wed Sep 10, 2008 10:34 am
by Darkzaelus
Only way you could do this is with multiple servers.
Not really much point in doing this in the grand scheme of things. PHP is often so fast that since there are transparent server assignments based on load, thats about as multithreaded as you can get.
And just to clear it up, pseudo-multithreading still aint multithreading.
Cheers, Darkzaelus
EDIT: I got beaten to a solution! Sorry!
Re: How to run second php script under the main script
Posted: Thu Sep 11, 2008 6:25 am
by girishkoshti007
Ok here is what i implemented, When ever i receive an SMS from the 2 sms companies all i do is make an insert into the database at 2 location.
The time consuming part of hitting the sms processing server is done by the runcommand type code that you posted in your first post.
the sms processing step happens independent of the insert process and has brought the execution of the first php file down from 2/3 secs to around 250 milliseconds since now it only contains inserts to the db.