Web service running time is slow and causing slow running web page - php

I"m using below third party code to send SMS for customers who are making orders in my web store, it seems this code is loading slowly and it's causing my order confirmation page (which has this code inside) to load slow.
is there any solution that I can use this code but it's slowness don't affect my page ?
Thanks
// Send SMS
/*
ini_set("soap.wsdl_cache_enabled", "0");
$sms_client = new SoapClient('http://87.107.121.54:2620/post/send.asmx', array('encoding'=>'UTF-8'));
$parameters['username'] = "xxxxxxxxxxx";
$parameters['password'] = "xxxx";
$parameters['to'] = "$phone";
$parameters['from'] = "1000947320";
$parameters['text'] ="test";
$parameters['isflash'] =false;
$sms_client->SendSimpleSMS2($parameters)->SendSimpleSMS2Result;
*/

Make the confirmation page add the values into database and create a script which processes the values from the database, meaning:
when user enters the page, your code will do something like this:
INSERT INTO sms SET to='$to', text='$text', sent=0;
and then you make a script which does the following:
ini_set("soap.wsdl_cache_enabled", "0");
$parameters['username'] = "xxxxxxxxxxx";
$parameters['password'] = "xxxx";
$parameters['from'] = "1000947320";
$parameters['isflash'] =false;
$sms_client = new SoapClient('http://87.107.121.54:2620/post/send.asmx', array('encoding'=>'UTF-8'));
$query = mysql_query("SELECT * FROM sms WHERE sent=0");
while( $message = mysql_fetch_assoc($query) ) {
$thisMessage = $parameters;
$thisMessage['to'] = $message['to'];
$thisMessage['text'] = $message['text'];
$sms_client->SendSimpleSMS2($thisMessage)->SendSimpleSMS2Result;
mysql_query('UPDATE sms SET sent=1 WHERE id='.$message['id']);
}
and you run this script in cron, lets say every minute or how often do you want to.

Related

twilio play hold music and redirecting to dial

Aim: I want that when the call is created it should play music instead of ringing and noone is available to pick call . after playing music it should say it.
after that it should redirect to feedback page
Now: call is created and mp3 is played when we pick the call and feedback page is running when it is dialling the call
So I want a solution to handle this
<?php
if (($nowtime >= $start_time) && ($nowtime <= $end_time)){
$the_mnum = $con ->load_field($the_id, 'the_mnum');
//$m= $the_mnum;
//echo $the_mnum;
?> <Say voice="woman">
We are directing your call to the therapist.
</Say>
<?php
$check_therapist = true;
$_SESSION["the_mnum"] = $the_mnum;
break;
}
}
if ($check_therapist){
$version = '';
$sid = '';
$token = '';
$client = new Services_Twilio($sid, $token, $version);
$call = $client->account->calls->create("+1", $the_mnum, "wekaw1.mp3", array());
echo $call->sid;
?>
<Redirect>feedback.php</Redirect>
<?php } else {?>
<Say voice="woman">
No listener is available right now.
We will give you a call back shortly when we have available listener.
</Say>
<?php } ?>
</Response>
In order to play hold music instead of rings before 2 numbers are connected you need to use <Enqueue> and <Queue> combined and initiate a call via our Rest API.
The following is an example implementation in PHP.
You need to assign the file below to your phone number. This code will <enqueue> the call and initiate a call forwarding to your number. This will also initiate a request to the second file that you need to create (modify_leg.php).
In some file first.php:
$name = $_POST['CallSid'];
echo '<Response><Enqueue>'.$name.'</Enqueue></Response>';
// Make sure to include php-helper library
require('../Services/Twilio.php'); // Loads the library
$account_sid = 'ACxxxxxxxxxxxxxxxxx';
$auth_token = 'aaxxxxxxxxxxx';
$from_number = '+1xxxxxx';
$to_number = '+1xxxxxxxx';
$client = new Services_Twilio($account_sid, $auth_token);
$message = $client->account->calls->create($from_number, $to_number, 'http://Your-FQDN/modify_leg.php?callSid='.$name);
Now in (modify_leg.php) you will pass $_GET[callSid] so it will actually connect both calls once you answer the phone and the caller will listen to music until you actually pick up the call.
<?php
$who = $_GET['callSid'];
?>
<Response>
<Dial><Queue><?php echo $who ?></Queue></Dial>
</Response>

Aweber does tno allow cron job

I can access this script directly via URL and it works fine but as a cron job ot doesnt work. Is it aweber or am I doing something wrong?
Awebre's documentation is one of the worst ones I have ever come across!
I am not sure why there is no explanation of this in their docs!
Thanks
<?php
include "wp-load.php";
include_once('wp-includes/class-phpass.php');
$sql = "SELECT member_id, email FROM wp_members_tbl WHERE aweber != 1";
$result = $wpdb->get_results($sql);
if(count($result)>0)
{
##Add aweber
require_once('aweber/aweber_api/aweber_api.php');
$consumerKey = '***';
$consumerSecret = '***';
$accessKey = '***'; # put your credentials here
$accessSecret = '***'; # put your credentials here
$account_id = '***'; # put the Account ID here
$list_id = '***'; # put the List ID here 3823593
$aweber = new AWeberAPI($consumerKey, $consumerSecret);
# Get an access token
if(empty($_COOKIE['accessToken']))
{
if (empty($_GET['oauth_token']))
{
$callbackUrl = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
list($requestToken, $requestTokenSecret) = $aweber->getRequestToken($callbackUrl);
setcookie('requestTokenSecret', $requestTokenSecret);
setcookie('callbackUrl', $callbackUrl);
header("Location: {$aweber->getAuthorizeUrl()}");
exit();
}
$aweber->user->tokenSecret = $_COOKIE['requestTokenSecret'];
$aweber->user->requestToken = $_GET['oauth_token'];
$aweber->user->verifier = $_GET['oauth_verifier'];
list($accessToken, $accessTokenSecret) = $aweber->getAccessToken();
setcookie('accessToken', $accessToken);
setcookie('accessTokenSecret', $accessTokenSecret);
header('Location: '.$_COOKIE['callbackUrl']);
exit();
}
##End add aweber
foreach($result as $val=>$row)
{
# Get AWeber Account
try {
$account = $aweber->getAccount($_COOKIE['accessToken'], $_COOKIE['accessTokenSecret']);
$listURL = "https://api.aweber.com/1.0/accounts/***/lists/".$list_id;
$list = $account->loadFromUrl($listURL);
$params = array(
'email' => $row->email
);
$subscribers = $list->subscribers;
$new_subscriber = $subscribers->create($params);
$update_data = array('aweber' => 1);
$where = array('member_id' => $row->member_id);
$wpdb->update( 'wp_members_tbl', $update_data, $where, $format = null, $where_format = null);
# success!
//print "A new subscriber was added to the $list->name list!";
}
catch(AWeberAPIException $exc)
{
print "<h3>AWeberAPIException:</h3>";
print " <li> Type: $exc->type <br>";
print " <li> Msg : $exc->message <br>";
print " <li> Docs: $exc->documentation_url <br>";
print "<hr>";
//exit(1);
}
}
}
Looks like a few places where this could be failing:
1) You have relative paths in your includes. The cron may not be able to find the included files. Try changing these to full paths.
2) Your code requires a browser environment (setting cookies, http header Location etc). None of this will work outside of a browser.
You should always execute the file from the command line as the user the cron runs as to test it. Any errors will be obvious.
To fix your issue you should use this tutorial which uses the browser to setup the credentials. After that it can be run from the command line/cron:
http://engineering.aweber.com/quick-start-api-script-in-php/
Try using this in the cron command:
wget -qO- http://yoururlhere/ &> /dev/null
It's not the best solution since "self calls" aren't recommended, but it'll keep you from dealing with environment settings.

Create new thread via script vbulletin

I have a script to create new thread with via scritp in vbulletin
// Create a new datamanager for posting
$threaddm =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
// Set some variable and information
$forumid = 87; // The id of the forum we are posting to
$userid = 2;
$_POST["title"] = $vinanghinguyen_title;
$_POST["content"] = $final_content; // The user id of the person posting
$title = $_POST["title"]; // The title of the thread
$pagetext = $_POST["content"]; // The content of the thread
$allowsmilie = '1'; // Are we allowing smilies in our post
$visible = '1'; // If the post visible (ie, moderated or not)
// Parse, retrieve and process the information we need to post
$foruminfo = fetch_foruminfo($forumid);
$threadinfo = array();
$user = htmlspecialchars_uni( fetch_userinfo($userid) );
$threaddm->set_info('forum', $foruminfo);
$threaddm->set_info('thread', $threadinfo);
$threaddm->setr('forumid', $forumid);
$threaddm->setr('userid', $userid);
$threaddm->setr('pagetext', $pagetext);
$threaddm->setr('title', $title);
$threaddm->set('allowsmilie', $allowsmilie);
$threaddm->set('visible', $visible);
// Lets see what happens if we save the page
$threaddm->pre_save();
if(count($threaddm->errors) < 1) {
// Basically if the page will save without errors then let do it for real this time
$threadid = $threaddm->save();
unset($threaddm);
} else {
// There was errors in the practice run, so lets display them
var_dump ($threaddm->errors);
}
/*======================================================================*\
It can create new thread with title, forumid, userid.....but it not insert tag. I want insert with this script. thank for help

Yii::app()->lang doesn't work sometimes with LimeSurvey

I am working on a custom script to automatically send out invites and reminders. I have everything working fine up until a point. My function to send invites looks like this:
function sendInvites($iSurveyID) {
$oSurvey = Survey::model()->findByPk($iSurveyID);
if (!isset($oSurvey)) {
die("could not load survey");
}
if(!tableExists("{{tokens_$iSurveyID}}")) {
die("survey has no tokens or something");
}
$SQLemailstatuscondition = "emailstatus = 'OK'";
$SQLremindercountcondition = '';
$SQLreminderdelaycondition = '';
$iMaxEmails = (int)Yii::app()->getConfig("maxemails");
$iMaxReminders = 1;
if(!is_null($iMaxReminders)) {
$SQLremindercountcondition = "remindercount < " . $iMaxReminders;
}
$oTokens = Tokens_dynamic::model($iSurveyID);
$aResultTokens = $oTokens->findUninvited(false, $iMaxEmails, true, $SQLemailstatuscondition, $SQLremindercountcondition, $SQLreminderdelaycondition);
if (empty($aResultTokens)) {
die("No tokens to send invites to");
}
$aResult = emailTokens($iSurveyID, $aResultTokens, 'invite');
}
I also have a simple little file that starts up Yii:
Yii::createApplication('LSYii_Application', APPPATH . 'config/config' . EXT);
Yii::app()->loadHelper('admin/token');
Yii::app()->loadHelper('common');
Everything works as expected up until I actually try to send emails to the tokens. I've tracked the problem down to the following, on of the functions called by emailTokens has this in it:
$clang = Yii::app()->lang;
$aBasicTokenFields=array('firstname'=>array(
'description'=>$clang->gT('First name'),
'mandatory'=>'N',
'showregister'=>'Y'
),
The Yii::app()->lang part seems to be causing issues because then php is unable to call the gT method. However, when LimeSurvey is running "properly" this never happens. I can't even seem to find where "lang" is in the LimeSurvey source.
What can I do to make it work?
Why do you make it so hard on yourself and not use the RemoteControl2 API ?
See http://manual.limesurvey.org/wiki/RemoteControl_2_API#invite_participants
On that page you will also find a PHP example script.
maybe
Yii::import('application.libraries.Limesurvey_lang');
$clang = new Limesurvey_lang($oTokens->language);

Wialon remote API login

My code:
<?php
if(isset($_GET['login']) && isset($_GET['login']) && isset($_GET['password'])){
$_login_url = "http://testing.wialon.com/wialon/ajax.html?svc=core/login&params={user:%s,password:%s}";
$login = $_GET['login'];
$password = $_GET['password'];
$handle = fopen(sprintf($_login_url, $login, $password), "r");
$line = fgets($handle);
fclose($handle);
$responce = explode(",",$line);
if(count($responce) < 2) {
echo "Invalid user or password";
} else {
$sessid = explode(":",$responce[1]);
$lastid = str_replace("\"","",$sessid[1]);
echo "http://testing.wialon.com/index.html?sid=".$lastid."";
}
}
?>
when I access this script with the server hosting the script everything works perfectly, The sessions are generated with my IP address.
But when I access it with another computer any user trying to login the script generates session using the servers IP address. can I send the request with the users IP address?
No, you cannot send the request with the users IP address.
However, you might be able to indicate that the request is being performed on behalf of another IP by using the HTTP_X_FORWARDED_FOR request header or similar, but without looking at their documentations (which doesn't seem to be publicly available) I can't be sure of it. You'll need to ask 'em.
This is an old thread but, let me put in my two cents. There are two new wialon athentication methods Token login and by passing the athorization hash . the second method is best suited for maintaining session across servers.
http://sdk.wialon.com/wiki/en/kit/remoteapi/apiref/core/create_auth_hash
http://sdk.wialon.com/wiki/en/kit/remoteapi/apiref/token/token
//get the Token from here http://hosting.wialon.com/login.html?client_id=wialon&access_type=-1&activation_time=0&duration=0&flags=1
// You should have your existing username from wialon with SDK access
$params = "{'token':'$token','operateAs','$username'}";
$baseurl = "http://hst-api.wialon.com/wialon/ajax.html";
$url = "$baseurl?params=".urlencode($params)."&svc=token/login";
$o = json_decode(file_get_contents($url),true);
$sid = $o['eid'];

Categories