Hie..I want help on a cakePHP script that will refresh or call a function in the controller after specified time interval.
public function testwebservices(){
ini_set("soap.wsdl_cache_enabled","0");
$options = array(
'soap_version'=>SOAP_1_2,
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE
);
$wsdl = "http://example.com/service.asmx?wsdl";
$client = new SoapClient($wsdl,$options);
$lastrec = rec5000;
$rec = $client->GetReceipt(array('txnRef'=>$lastrec));
$result = $rec->GetReceiptRez;
i want to call the above function to so that it will be automatically executed after a specified time.
Thank you in advance
You’re best bet is to go with a cron-task (if you’re on a Unix/Linux machine). The cron task could be written in a couple of ways.
First: You could call your script directly with the PHP interpreter and the script you’d run in your cron may look like
However, you’ll need to take notice that you will not get the benefits of your framework. That means that any framework utilities that you are using, you will have to load yourself in your
script.phpfile. If this is too much (loading all the required utils), then you can do it another way.Second: You can create an endpoint, such as
/test/web-serviceand you can setup a cron to make a web-request to that script which will check that the web service is running correctly. In that case you would have a simply cURL request that might look like:The benefit of this approach is that you could really put this on any machine (if you make the URL public) and you get the benefit of having your framework (cakePHP in this case) being loaded and all of the utils being available to you.