Jump to content

don't wait function after call


bluetoother

Recommended Posts

what is the way to run functions that do not stop or slow the execution of rest php code .in other words : call a function in php page and continue execution the php code below the call statement , while the function is running ( concurrent running ).i solved this using AJAX call but you know this depend on the client's actions when client ask for a page .

Link to comment
Share on other sites

Quite honestly, I don't think there is a way. PHP is a language where calls are made and processed immediately. If it didnt, then your code would put out errors beyond reason, because how is php to know that you are to call the function, then continue immedately on one call, and then suddenly know that you wait for this function to finish before going on with code. Although I'm not an expert in PHP code and function manipulation, but honestly, I've never seen it done where i can call the strpos function and call array_pop 3 lines down before the strrpos finishes.

Link to comment
Share on other sites

solving this issue may help webmasters who use hosting plans that don't support cron jobsfor example you want some code to run every 15 min's and your control panel does not support creating cron jobsthis code may do some sorting in database for examplei solved this by calling some function when some page get requested in my web sitebut i discovered running the sorting code slow down the view of the requested pagei solved this again by forcing the client's browser to call php page that contain the sorting code using ajax requestwith out having to wait a result from the AJAX requestbut i cannot depend on client's browser every time,maybe that page contain alot of AJAX requests and adding new request may slow down the view or cause an error in the browser.

Link to comment
Share on other sites

Oh right! Reading your first post, I thought you meant as in

Seq. Exec.				  Seq. Exec.	 |						   |	 |						   |	 |						   |	 |						   |	 |						   |	 |			 opposed	   |	 |			   to:		 |	 +Func. Call				 -Func. Call	 |	|							|	 |	|							|	 |	|							|	 |	|							|	 |	|							|	 |	-					  Return-	 |						   |	 |						   |	 V						   V

The server can of course run more than one PHP script at once, but you would need to fiddle with its settings so that the scripts don't have to be called from client machines.

Link to comment
Share on other sites

You can fork the process if you want to create a new processing thread that isn't going to slow down the first thread.http://www.php.net/manual/en/function.pcntl-fork.phpBut that's not going to do something like "run a process every 15 minutes". Considering that the default max execution time of a PHP script is 30 seconds, if you think you're going to write a script that checks for things to be done every X minutes then you're wrong. That's specifically what cron is for. If they don't have cron, PHP is not the solution, C is the solution.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...