Run another function in controller class - Background process |
[eluser]tonanbarbarian[/eluser]
if we make an instance of CI in the constructor of the library we can do anything Code: <?php So if you want to call anything you could in the controller use $this->CI->... rather than $this->...
[eluser]cinewbie81[/eluser]
Hi tonanbabarian, $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30) return me true .. and now im confuse where should i write code / function to send the sms ??
[eluser]tonanbarbarian[/eluser]
This library is a way of calling code in another controller by requesting the page in a similar fashion to a browser would. So create the code you were going to create in the SendSMS controller $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30); opens a connection (like tying in location bar of the browser) to the site www.example.com $request = "GET /SendSMS/index HTTP/1.1\r\n" is requesting the url /SendSMS/index from the site so it is basically requesting the following http://www.example.com/SensSMS/index So put the code to send the sms in the SendSMS controller (or change the code I have given you to the correct Controller and Model in the url)
[eluser]xwero[/eluser]
Cron is an application on your server that takes care of repetitive tasks. If you have a a management interface from your hoster like cpanel you will see it as an option. The only thing you need to do is writing a script for something you want to do and direct the cron to that url and set up an interval.
[eluser]Negligence[/eluser]
You might be able to do something like this in your Main index function, but play around with the code, I haven't tested it. Code: public function index()
[eluser]cinewbie81[/eluser]
tonanbarbarian :- Here's what i do: Code: class sms { ![]() xwero - I still struggling to write a cron script to execute the function in the controller .. Negligence - your function might work, but it doesnt execute the statement background isn't it ?
[eluser]cinewbie81[/eluser]
Ok I have the following two files: a) sms.php (controller file), b) background.php (not a controller file, and it's in controller though) a) sms.php Code: <?php b) background.php Code: <?php When i browse www.mysite.com/index.php/sms/sendsms, it will send the sms successfully, but of course it's not background process. So i try to create another function in my Sms controller call backgroundprocess() as shown above. Now when i browse www.mysite.com/index.php/sms/backgroundprocess , it didnt send me any sms ... any idea why ?
[eluser]Ciaro[/eluser]
[quote author="tonanbarbarian" date="1197028875"]try something like this (totally untested) you use fsockopen to make a connection to the url, writing the data of the request, then just close the socket without reading the reply Code: $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30); Great solution. Really helped me alot. Thanks for sharing! |
Welcome Guest, Not a member yet? Register Sign In |