CodeIgniter Forums
How to request and url without expect the response - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to request and url without expect the response (/showthread.php?tid=11159)



How to request and url without expect the response - El Forum - 08-28-2008

[eluser]Ryubr[/eluser]
Hello,

I have tried to find a solution on the boards, nothing so far. My question is, i have in my Model class one function to add some data to a database and at the end to do a get or post for an external url just to signal it "i did it", but i don't want to expect the answer bacause it could delay the response to the application on my side if the external url is too slow or off-line. Just like ajax, but in this case server side, i would like to send the request and go on without wait for it to finish.

Any ideias about how to do it?

Thanks in advance


How to request and url without expect the response - El Forum - 08-28-2008

[eluser]drewbee[/eluser]
Sure. Check out PHP's exec() function. It lets you drop into the background and execute / run shell commands. In your case, you would want to run a php file. This will execute it in the background while your normal page can go on.

function.exec()

ex.
Code:
exec(escapeshellcmd("php path/to/file -s"))



How to request and url without expect the response - El Forum - 08-28-2008

[eluser]SitesByJoe[/eluser]
You could also use the Curl library to run remote requests. Works well for me!


How to request and url without expect the response - El Forum - 08-28-2008

[eluser]Ryubr[/eluser]
Thanks for the reply, but what i need is something like the curl but that does not "hold" the execution, unfortunatelly i will not be able to use the exec :-(


How to request and url without expect the response - El Forum - 08-28-2008

[eluser]drewbee[/eluser]
Why can you not use exec? That should be available on even a shared server? As well, you could look into forking. The exec should reside on the external server. As curl posts to it, it runs the exec command all the while curl thinks everything is honkey doorey!

Or if you don't have access to the exerternal server, use exec() to issue the curl command out to the external server.