I'm trying to get records from a server using PHP. When I run the code below using XAMPP, it works without any issue. However, when I upload the code to my web host (infinityfree), the request no longer works. The error I receive is Server is offline.
Please see my code below:
try
{
$rQuery = new QueryServer( $serverIP, $serverPort );
$aInformation = $rQuery->GetInfo( );
$aServerRules = $rQuery->GetRules( );
$aBasicPlayer = $rQuery->GetPlayers( );
$aTotalPlayers = $rQuery->GetDetailedPlayers( );
$rQuery->Close( );
}
catch (QueryServerException $pError)
{
echo 'Server is offline';
}
Any help is appreciated.
I am trying to get all my MLS listing via PHP using PHRETS which I downloaded from here:
https://github.com/dangodev/PHRETS-Example/blob/master/lib/phrets.php
and I used this example to download my listings into a csv format:
https://github.com/troydavisson/PHRETS/wiki/Connect,%20download%20listing%20data%20in%20CSV%20format,%20disconnect
I got the RETS URL, username and password from my MLS board, but I still can’t connect.
My code returns false when call the PHRETS library here:
require_once("phrets.php");
// start rets connection
$rets = new phRETS;
echo "+ Connecting to {$rets_login_url} as {$rets_username}<br>\n";
$connect = $rets->Connect($rets_login_url, $rets_username, $rets_password);
if ($connect) {
echo " + Connected<br>\n";
}
else {
echo " + Not connected:<br>\n";
print_r($rets->Error());
exit;
}
When I goto to library and look at the method Connect, that code returns false here:
// make request to Login transaction
$result = $this->RETSRequest($this->capability_url['Login']);
if (!$result) {
return false;
}
And when I look at my RETSRequest Method, it returns false here because the response code is 0 and not 200
if ($response_code != 200) {
$this->set_error_info("http", $response_code, $response_body);
return false;
}
and here is where its trying to connect:
if ($this->ua_auth == true) {
$session_id_to_calculate_with = "";
// calculate RETS-UA-Authorization header
$ua_a1 = md5($this->static_headers['User-Agent'] .':'. $this->ua_pwd);
$session_id_to_calculate_with = ($this->use_interealty_ua_auth == true) ? "" : $this->session_id;
$ua_dig_resp = md5(trim($ua_a1) .':'. trim($this->request_id) .':'. trim($session_id_to_calculate_with) .':'. trim($this->static_headers['RETS-Version']));
$request_headers .= "RETS-UA-Authorization: Digest {$ua_dig_resp}\r\n";
}
$this->last_request_url = $request_url;
curl_setopt($this->ch, CURLOPT_URL, $request_url);
curl_setopt($this->ch, CURLOPT_HTTPHEADER, array(trim($request_headers)));
// do it
$response_body = curl_exec($this->ch);
$response_code = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
Why can’t I connect?
I was able to login via http://retsmd.com with the url, username and password. I really need to get my listings in the format of CSV.
PLEASE HELP
I do have curl installed on my server, I checked with this method:
Check to see if cURL is installed locally?
A response code of 0 usually indicates that your server failed to open a connection with the server, likely due to firewall issues between you and them. Some RETS servers still run on a port 6103, so if your server (hosting company, etc.) prevent outbound connections from being opened on that port, that could be the cause for what you're seeing.
I'd recommend trying your code example from a different server or computer that doesn't have any connection restrictions. You could also try https://retsmd.com/auth as a way to verify that the credentials you've been given will work (assuming your local environment has what it needs for PHRETS to run).
Adding to troydavisson's answer,
You can include the following extra line of code to get the log of your connection for checking the issue.
// start rets connection
$rets = new phRETS;
$rets->SetParam('debug_mode', true);//extra line of code to get log
You will get full log in the rets_debug.txt file.
I have tried to get the image from gallery and upload the selected image to server using webservices in titanium.
I have used below code. But am getting the debug error : HTTP error And also it shows the alert box like "There was an error during the connection"
This code is working fine in my development server.But it is not working in my client server. What's the reason ? why my code is not working in my client server ?
The file upload is working fine when upload the file from android device.But it's not working while upload a file from iphone device.Can you please give me a idea to resolve this issue ?
Why am getting this error on my console window.
function AUF_ADD_File_FolderData () {
Titanium.Media.openPhotoGallery({
success:function(event) {
var request = Ti.Network.createHTTPClient({
onload : function(e) {
Ti.API.info(this.responseText);
Ti.API.info("image pathe"+" "+event.media);
if(this.responseText == "Successfully file is created"){
var managefolders =Alloy.createController('manage_folders').getView();
managefolders.open();
}
else{
alert(this.responseText);
}
},
onerror: function(e){
Ti.API.debug(e.error);
alert("There was an error during the connection");
},
timeout:20000,
});
var uploadabc = event.media.imageAsResized(400 , 400);
request.open("POST",url+"client/manager/at_manager_create_common_file.php");
var params = ({"manager_id": manager_id,"file": uploadabc,});
// var params = ({"manager_id": manager_id,"file": event.media,});
request.send(params);
},
cancel:function() {
// called when user cancels taking a picture
},
error:function(error) {
// called when there's an error
var a = Titanium.UI.createAlertDialog({title:'Camera'});
if (error.code == Titanium.Media.NO_CAMERA) {
a.setMessage('Please run this test on device');
} else {
a.setMessage('Unexpected error: ' + error.code);
}
a.show();
},
saveToPhotoGallery:false,
// allowEditing and mediaTypes are iOS-only settings
allowEditing:true,
mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO]
});
}
EDIT:
this is php file :
<?php
$request = base64_decode($_POST['jsondata']);
$data = json_decode($request,true);
$manager_id = $data['manager_id'];
$file_name = $data['file_name'];
$source = base64_decode($data['source']);
include "db_connect.php";
// connecting to db
$db = new DB_CONNECT();
$result = mysql_query("SELECT * from at_common_files WHERE user_id = '$manager_id' and file_name = '$file_name'");
$no_of_rows = mysql_num_rows($result);
if ($no_of_rows > 0) {
$response='{"Error":"1","Message":"Filename already existed"}';
echo $response;
} else {
$upload_dir = 'common_files/'.$manager_id."_".$file_name;
file_put_contents($upload_dir,$source);
$qugery = mysql_query("insert into at_common_files (user_id,file_name) values ($manager_id, '$file_name') ");
$response = '{"Error":"0","Message":"Successfully file is created"}';
echo $response;
}
?>
EDIT:
As am getting the below error :
: [DEBUG] HTTP error
: [INFO] IN ERROR {"type":"error","source":{"cache":false},"code":404,"error":"HTTP error","success":false}
if i have call the same url and pass a manager_id alone , am getting the results fine.if i have passing the manager_id and file, this time only am getting the Http error. i can't find a exact issue.Because the same titanium code and php code (development server)is working fine and the image is uploading to development server folder. but i have moved the same php file to my client server.now it is not working . also the same web service url is working fine in browser and android.it's not working in iphone only.so that exactly i can't find where is the issue ? can you please give me a solutions.
EDIT :
please refer the below link:
http://developer.appcelerator.com/question/174462/image-not-uploading-from-iphone#comment-224007
I have facing a exact same issue.could you please give me a solution.
i have found many questions like this (e.g. The 'Passive' connection '<appname>' access to protected services is denied).
the answer is always:
"This error is what's known as a "Red Herring". It's a clue that's misleading. The HID isn't a real error that affects your app. There should be other messages that may indicate what's going on."
so look if there is a other error massege which describes your problem.
for example try to escape the filename you are using within the sql statements:
$file_name = mysql_real_escape_string($data['file_name']);
Make sure your device is connected to the internet and then try it like this:
Titanium:
function AUF_ADD_File_FolderData () {
Titanium.Media.openPhotoGallery({
success:function(event) {
var xhr = Titanium.Network.createHTTPClient();
xhr.onerror = function(e){
Ti.API.info('IN ERROR ' + JSON.stringify(e));
alert('Sorry, we could not upload your photo! Please try again.');
};
xhr.onload = function(){
Ti.API.info(this.responseText);
Ti.API.info("image pathe"+" "+event.media);
if(this.responseText == "Successfully file is created"){
var managefolders =Alloy.createController('manage_folders').getView();
managefolders.open();
}else{
alert(this.responseText);
}
};
xhr.open('POST', url+"client/manager/at_manager_create_common_file.php");
xhr.send({
media: event.media,
manager_id: manager_id
});
},
cancel:function() {
// called when user cancels taking a picture
},
error:function(error) {
// called when there's an error
var a = Titanium.UI.createAlertDialog({title:'Camera'});
if (error.code == Titanium.Media.NO_CAMERA) {
a.setMessage('Please run this test on device');
} else {
a.setMessage('Unexpected error: ' + error.code);
}
a.show();
},
saveToPhotoGallery:false,
// allowEditing and mediaTypes are iOS-only settings
allowEditing:true,
mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO]*/
});
}
PHP:
<?php
//this function returns a random 5-char filename with the jpg extension
function randomFileName()
{
$length = 5;
$characters = 'abcdefghijklmnopqrstuvwxyz';
$string = '';
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}
return $string . '.jpg';
}
//create the random filename string and uploads target variables
$randomString = randomFileName();
$target = 'common_files/'.$randomString;
if(move_uploaded_file($_FILES['media']['tmp_name'], $target))
{
echo "success";
}
else
{
echo "moving to target failed";
}
?>
For more info check this link: http://code.tutsplus.com/tutorials/titanium-mobile-build-an-image-uploader--mobile-8860
If it works like this you will have to add your logic again (resizing and manager_id)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Edit: Just ran into a wrinkle, I just got this working on an iPhone over the weekend and just out of curiosity ran it on two phones at once and it worked. So it ran happily along (as I expected it to the first time) when one phone was an iPhone (iOS 6) and the other was HTC One (Android 4.3). This was however on another person's WIFI. Could my home WIFI be a factor in blocking two devices going to the same location? (The second phone I was using when it didn't work was a Samsung Galaxy Ace 2 (Android 2.3))
So I've got this problem. I am using PhoneGap and coming up with a basic quiz system to muck around with. I've got it working and I'm having a great time. It works essentially through a web console where I can set up a quiz and cycle through questions and with a not so complex series of status updates to an underlying database I use Ajax calls from my mobile to read the status and display a question or wait for the next one.
Basic call is:
$(function checkForQuestion() {
var postData = "stuff needed in called PHP";
$.ajax({
type: "POST",
data: postData,
url: "my called php",
success: function(data){
var result = JSON.parse(data);
if (result == "question") {
--Display Question
} else {
setTimeout(checkForQuestion, 1000);
return false;
}
});
return false;
});
In my limited experience this seems to be a general use of Ajax with a recursive call back if it needs to wait for a new status.
Now this isn't everything by far, but a taster of what I'm doing. It works extremely well with one mobile device and a web console happily working through quizzes.
When I attempt to add a second mobile (haven't even attempted three yet) what happens is the second mobile just silently fails where it is supposed to be calling this ajax. Now the second mobile can quite happily chug along with this on it's own so it shouldn't be a hardware issue. There are no errors thrown out in the PHP, and with a little logging I can't find anything obviously failing.
At this point I thought, perhaps there is a limit on connections on my web host (I'm just using a shared server web host I'm using to test this out) and there are but that is limited to 20 entry processes with Cloud Linux LVE. However This should not preclude two mobiles calling the same PHP (via wifi) at roughly the same time. It should just run the calls concurrently and one will return slight faster than the other (or that is my understanding).
I thought perhaps this is a lock put on the MySQL database I'm using not allowing multiple users/PHP to query it at roughly the same time, but the consecutive nature of PHP should rule that out and some Googling assures me that calls will be queued.
I'm guessing that what is happening is the two calls come in and without returning any error one silently conflicts with the other causing a fail, but I have no idea hwo to find the fail and fix it.
Any suggestions?
Request for the actual code:
$(function () {
$(document).on("pagebeforeshow", "#page6", function () {
document.getElementById("mob_user_name2").innerHTML = window.localStorage.getItem("mob_local_login_name");
$(function checkForQuestion() {
//sort out the data to be posted
var postData = "mob_quizwait_quizcode=" . concat(window.localStorage.getItem("mob_local_quiz_code"), "&mob_quizwait_email=", window.localStorage.getItem("mob_local_login_email"), "&mob_quizwait_password=", window.localStorage.getItem("mob_local_login_password"), "&mob_quizwait_questionid=", window.localStorage.getItem("mob_question_id"));
$.ajax({
type: "POST",
data: postData,
url: "url of php",
success: function(data){
var mob_quizwait_data = JSON.parse(data);
if (mob_quizwait_data.mob_quizwait_success == "mob quizwait go") {
window.localStorage.setItem("mob_question_id", mob_quizwait_data.mob_quizwait_questionid);
window.localStorage.setItem("mob_question_score", mob_quizwait_data.mob_quizwait_score);
window.localStorage.setItem("mob_question_category", mob_quizwait_data.mob_quizwait_category);
window.localStorage.setItem("mob_question_question", mob_quizwait_data.mob_quizwait_question);
window.localStorage.setItem("mob_answer1", mob_quizwait_data.mob_quizwait_correct);
window.localStorage.setItem("mob_answer2", mob_quizwait_data.mob_quizwait_wrong1);
window.localStorage.setItem("mob_answer3", mob_quizwait_data.mob_quizwait_wrong2);
window.localStorage.setItem("mob_answer4", mob_quizwait_data.mob_quizwait_wrong3);
$.mobile.changePage("#page7", {transition:"slide", changeHash:false});
} else if (mob_quizwait_data.mob_quizwait_success == "mob quizwait stay") {
setTimeout(checkForQuestion, 1000);
return false;
} else if (mob_quizwait_data.mob_quizwait_success == "mob quizwait intermission") {
document.getElementById("mob_intermission").innerHTML = "Intermission";
$.mobile.changePage("#page6", {transition:"none", changeHash:false});
} else if (mob_quizwait_data.mob_quizwait_success == "mob quizwait finish") {
$.mobile.changePage("#page8", {transition:"slide", changeHash:false});
} else {
navigator.notification.alert("Status Check Failed. Please Try Again.", function(){}, "Alert", "OK");
}
}
});
return false;
});
});
});
And the PHP:
<?PHP
include '../open.php';
//take in POST variables
$quizcode = $link->real_escape_string($_POST["mob_quizwait_quizcode"]);
$email = $link->real_escape_string($_POST["mob_quizwait_email"]);
$password = $link->real_escape_string($_POST["mob_quizwait_password"]);
$questionid1 = $link->real_escape_string($_POST["mob_quizwait_questionid"]);
$quizid = 0;
$status = "X";
$questionid = 0;
$sql = "SELECT QUIZ_ID FROM B_QUIZ WHERE QUIZ_CODE = '$quizcode'";
$res = $link->query($sql);
while ($row = $res->fetch_array()) {
$quizid = $row['QUIZ_ID'];
}
$sql = "SELECT USER_ID FROM A_USER WHERE USER_EMAIL = '$email' AND USER_PASSWORD = '$password'";
$res = $link->query($sql);
while ($row = $res->fetch_array()) {
$userid = $row['USER_ID'];
}
$sql = "SELECT QUIZ_STATUS, IFNULL(QUESTION_ID, 0) AS QUESTION_ID FROM B_GAME WHERE QUIZ_ID = $quizid";
$res = $link->query($sql);
while ($row = $res->fetch_array()) {
$status = $row['QUIZ_STATUS'];
$questionid = $row['QUESTION_ID'];
}
if ($questionid == $questionid1) {
$questionid = 0;
}
if ($status != "F") {
if ($quizid != 0 && $status != "X") {
//get details to be written to the profile page
if ($questionid != 0) {
$sql = "SELECT SCORE FROM B_PARTICIPANT WHERE USER_ID = $userid AND QUIZ_ID = $quizid";
$res = $link->query($sql);
while ($row = $res->fetch_array()) {
$score = $row['SCORE'];
}
$sql = "SELECT b.QUESTION_ID, c.CATEGORY, b.QUESTION, b.CORRECT_ANSWER, b.WRONG_ANSWER_1, b.WRONG_ANSWER_2, b.WRONG_ANSWER_3
FROM B_GAME a, B_QUESTION b, D_CATEGORY c
WHERE a.QUESTION_ID = b.QUESTION_ID
AND b.CATEGORY_ID = c.CATEGORY_ID
AND a.QUIZ_ID = $quizid";
$res = $link->query($sql);
while ($row = $res->fetch_array()) {
$questionid = $row['QUESTION_ID'];
$category = $row['CATEGORY'];
$question = $row['QUESTION'];
$correct = $row['CORRECT_ANSWER'];
$wrong1 = $row['WRONG_ANSWER_1'];
$wrong2 = $row['WRONG_ANSWER_2'];
$wrong3 = $row['WRONG_ANSWER_3'];
}
if ($status == "R") {
$arr = array("mob_quizwait_success" => "mob quizwait go",
"mob_quizwait_questionid" => $questionid,
"mob_quizwait_score" => $score,
"mob_quizwait_category" => $category,
"mob_quizwait_question" => $question,
"mob_quizwait_correct" => $correct,
"mob_quizwait_wrong1" => $wrong1,
"mob_quizwait_wrong2" => $wrong2,
"mob_quizwait_wrong3" => $wrong3);
echo json_encode($arr);
} else if ($status == "N") {
$arr = array("mob_quizwait_success" => "mob quizwait stay");
echo json_encode($arr);
} else if ($status == "I") {
$arr = array("mob_quizwait_success" => "mob quizwait intermission");
echo json_encode($arr);
}
} else {
$arr = array("mob_quizwait_success" => "mob quizwait stay");
echo json_encode($arr);
}
} else {
$arr = array("mob_quizwait_success" => "mob quizwait failed");
echo json_encode($arr);
}
} else {
$arr = array("mob_quizwait_success" => "mob quizwait finished");
echo json_encode($arr);
}
include '../close.php';
?>
open.php:
<?PHP
//DATABASE DETAILS//
$DB_ADDRESS = "yeah";
$DB_USER = "not";
$DB_PASS = "gonna";
$DB_NAME = "do it";
//Connect to the MySQL database
$link = new mysqli($DB_ADDRESS, $DB_USER, $DB_PASS, $DB_NAME);
if (mysqli_connect_errno()) {
printf("Connect Failed: %s\n", mysqli_connect_error());
exit();
}
?>
close.php:
<?PHP
mysqli_close($link);
?>
The silent fail may be because there is a server error when processing the ajax call.
Add an error handler to the ajax call.
$.ajax({
type: "POST",
data: postData,
url: 'url of php',
success: successFunction(),
error: function(xhr, status, err) { alert("Ajax request failed"); }
});
You may need to step through PHP code or add additional logging to see the flow of the application.
Try:
<script>
var st_flag = true;
$(function () {
$(document).on("pagebeforeshow", "#page6", function () {
document.getElementById("mob_user_name2").innerHTML = window.localStorage.getItem("mob_local_login_name");
$(function checkForQuestion() {
if(!st_flag)
{
setTimeout(checkForQuestion, 1000);
}
//sort out the data to be posted
var postData = "mob_quizwait_quizcode=" . concat(window.localStorage.getItem("mob_local_quiz_code"), "&mob_quizwait_email=", window.localStorage.getItem("mob_local_login_email"), "&mob_quizwait_password=", window.localStorage.getItem("mob_local_login_password"), "&mob_quizwait_questionid=", window.localStorage.getItem("mob_question_id"));
$.ajax({
type: "POST",
data: postData,
url: "url of php",
st_flag = false;
success: function(data){
var mob_quizwait_data = JSON.parse(data);
if (mob_quizwait_data.mob_quizwait_success == "mob quizwait go") {
window.localStorage.setItem("mob_question_id", mob_quizwait_data.mob_quizwait_questionid);
window.localStorage.setItem("mob_question_score", mob_quizwait_data.mob_quizwait_score);
window.localStorage.setItem("mob_question_category", mob_quizwait_data.mob_quizwait_category);
window.localStorage.setItem("mob_question_question", mob_quizwait_data.mob_quizwait_question);
window.localStorage.setItem("mob_answer1", mob_quizwait_data.mob_quizwait_correct);
window.localStorage.setItem("mob_answer2", mob_quizwait_data.mob_quizwait_wrong1);
window.localStorage.setItem("mob_answer3", mob_quizwait_data.mob_quizwait_wrong2);
window.localStorage.setItem("mob_answer4", mob_quizwait_data.mob_quizwait_wrong3);
$.mobile.changePage("#page7", {transition:"slide", changeHash:false});
st_flag = true;
} else if (mob_quizwait_data.mob_quizwait_success == "mob quizwait stay") {
setTimeout(checkForQuestion, 1000);
return false;
} else if (mob_quizwait_data.mob_quizwait_success == "mob quizwait intermission") {
document.getElementById("mob_intermission").innerHTML = "Intermission";
$.mobile.changePage("#page6", {transition:"none", changeHash:false});
} else if (mob_quizwait_data.mob_quizwait_success == "mob quizwait finish") {
$.mobile.changePage("#page8", {transition:"slide", changeHash:false});
} else {
navigator.notification.alert("Status Check Failed. Please Try Again.", function(){}, "Alert", "OK");
}
}
});
return false;
});
});
});
</script>
Wait for first call to be complete.
Even though your problem is complicated by nature and I've got no reason to come to the conclusion I'm going to say but my bets are on session.auto_start.
As I see you've got no use for session in your code and in your case it might be a problem starting it. Set session.auto_start to false so your code won't use sessions at all and then test your code. It's a long shot but it's the best I've got.
To explain myself, php makes use of files for sessions by default. And it does so by opening the file in exclusive mode. It means if one request is running on the server, the second one with the same session_id will be blocked until the first one realizes it. So each browser can have only one request executed on the server at a time. I know your javascript won't be making the second request before the first one is returned but as I said your problem is complicated and it's the only guess I could come up with and I believe it's worth a test.
So my solution is: make sure you are not using sessions at all.
As Kami said, i think there should be some issues in the server side(PHP) only. And lot of time, PHP don't used to show the errors due to the server settings. I would suggest you to check the apache error logs, so that you can get to know if any unshown error is present. To check this, just load the URL which is having the problem and then check the error log usually present in var/log/ folder.
I have a strange suggestion after your edit. Wifi hotspot hides real adresses by NAT so from server's point of view both your devices has the same IP address. Server sends the answer to your Wifi spot and it route the packets to real addresses. Sometimes I had package missing but I can't remember the situation when all packets had been lost.
You should request the page from both devices and log the scrpit's work result on the server side. If there was 2 requests and all DB requests worked properly that means that one of your clients didn't get the response. It is probably because of your router, probably NAT
This turned out to be an unknown issue with the Web Host provider. Despite more than a dozen detailed requests for what on their side was blocking things I was always referred to how my own equipment or own code was at fault.
Set myself up a VPS and presto change-o I have a working system with no modifications to the code or the equipment.
TIL I don't like people who cover up their incompetency by blaming others.
I am using javascript to connect websocket:
<script>
var socket;
var host = "ws://localhost:8000/socket/server/startDaemon.php";
var socket = new WebSocket(host);
</script>
I got the error:
Can't establish a connection to the server at
var host = "ws://localhost:8000/socket/server/startDaemon.php";
var socket = new WebSocket(host);
How can I solve this issue?
NOTE : I enabled websocket in mozilla to support web socket application.
and when i run in chrome i got error:
can't establish a connection to the server at ws://localhost:8000/socket/server/startDaemon.php. var socket = new WebSocket(host);
Apparently firefox 4 has websockets disabled because of vulnerabilities. To quote From this article:
WebSocket disabled in Firefox 4
Recent discoveries found that the protocol that Websocket works with is vulnerable to attacks. Adam Barth demonstrated some serious attacks against the protocol that could be used by an attacker to poison caches that sit in between the browser and the Internet.
I solved my error by following code through this link
http://www.flynsarmy.com/2010/05/php-web-socket-chat-application/
and created socketWebSocketTrigger.class.php file for response message where code as
class socketWebSocketTrigger
{
function responseMessage($param)
{
$a = 'Unknown parameter';
if($param == 'age'){
$a = "Oh dear, I'm 152";
}
if($param == 'hello'){
$a = 'hello, how are you?';
}
if($param == 'name'){
$a = 'my name is Mr. websocket';
}
if($param == 'today'){
$a = date('Y-m-d');
}
if($param == 'hi'){
$a = 'hi there';
}
return $a;
}
}
and added code in send function of 'WebSocketServer.php' for calling 'responseMessage' function which response request message
public function send($client, $msg){
$this->say("> ".$msg);
$messageRequest = json_decode($msg,true);
// $action=$messageRequest[0];
$action = 'responseMessage';
$param = $messageRequest[1]['data'];
if( method_exists('socketWebSocketTrigger',$action) ){
$response = socketWebSocketTrigger::$action($param);
}
$msg = json_encode(
array(
'message',
array('data' => $response)
)
);
$msg = $this->wrap($msg);
socket_write($client, $msg, strlen($msg));
}
it's working great.
Are you trying to run the client in Firefox? According to the documentation:
As of Feb/10 the only browsers that
support websockets are Google Chrome
and Webkit Nightlies. Get it from here
http://www.google.com/chrome
Try running it in Chrome and see if that works for you.
First of all your mistake is using php function with javascript require_once 'WebSocket.php'; and secondly go through the tutorial as in the link below.
http://net.tutsplus.com/tutorials/javascript-ajax/start-using-html5-websockets-today/
it's working fine.
Thanks,