Run another function in controller class - Background process |
[eluser]cinewbie81[/eluser]
Hi all, In my "Main" Controller index function, i want to call the index() function from "SendSMS" controller class. How can i do it ? I know it can be done using redirect("SendSMS") statement, but I don't want it to be this way. Instead, i want the SendSms index() function to be running as background process(using the '&' symbol). How can i do it ? Anyone ?? Thanks. Code: <?php Code: <?php
[eluser]tonanbarbarian[/eluser]
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);
[eluser]cinewbie81[/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); I'm totally lost ... when and where should i write the statement to send the sms ??
[eluser]xwero[/eluser]
The way i would do this is to set up a cron task for the sendsms (class???) function where i would check in the database the messages that haven't been send already. Background tasks are less recourse demanding using cron than php alternatives.
[eluser]cinewbie81[/eluser]
Hi xwero, mind to elaborate ? I dont quite understand what do u mean ![]() btw, if using the way i'm current working on, is there any solution ?
[eluser]xwero[/eluser]
Instead of a background class you just write a function(s) and set up a cron task(s) to process the function. Code: class Main extends Controller { I don't know how you are going to trigger when an sms has to be send but i guess you want it send when they click submit that's why you want to run the background script. Does it matter if it's send that instant or after a minute or two ,or three. Using a cron script that runs every minute you can control the flood of messages so it doesn't overload the sms server/service. But you are free to choose your own interval of course ![]()
[eluser]cinewbie81[/eluser]
Thanks. But may i know what is cron task ? and how to setup a cron task to process those function ?? P/S: It's acceptable if the SMS send a minute later !!
[eluser]tonanbarbarian[/eluser]
put my code anywhere you want. put it in a library maybe and then when you want the process to run call it library/sms.php Code: <?php then when you want to send the sms dont go to another controller just use the library Code: class Main extends Controller { as I stated before I am not sure this will work but it is fairly quick to setup and worth a try
[eluser]cinewbie81[/eluser]
hi tonanbarbarian, I need to use some of the CI built in function in function background(), for eg: this->db->query(), but inside the library it doesn't allow me to do so ...
[eluser]nmweb[/eluser]
Sure it does, http://ellislab.com/codeigniter/user-gui...aries.html check under 'Utilizing CodeIgniter Resources within Your Library' |
Welcome Guest, Not a member yet? Register Sign In |