Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts
Nov 25, 2018
Feb 3, 2018
Node Redis Socket.io PHP Simple example to publish a message
pusher.php
<?php
//Load the Predis autoloader
require("Predis/autoload.php");
//Register all classes
Predis\Autoloader::register();
//Create a redis client to publish event
$redis = new Predis\Client(array(
"scheme" => "tcp",
"host" => "127.0.0.1",
"port" => 6379
));
//Publish the event
$redis->publish("mychannel", "Woooow there !!!");
?>
pusher.js
var app = require('express')();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var redis = require('redis');
server.listen(8080);
io.on("connection", function (socket) {
console.log("new client connected");
var redisClient = redis.createClient();
redisClient.subscribe('mychannel');
redisClient.on("message", function(channel, message) {
console.log("mew message in queue channel");
socket.emit("schannel", message);
});
socket.on('disconnect', function() {
redisClient.quit();
});
});
receiver.html
<!doctype html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2" >
<div id="messages" >ss</div>
</div>
</div>
</div>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="http://localhost:8080/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost:8080');
socket.on("schannel", function(message) {
$( "#messages" ).append( "<p>"+message+"</p>" );
console.log("tweet from", message);
console.log("contents:", message);
});
</script>
</body>
</html>
That's all. You are done....
You can monitor redis messages using following command
redis-cli monitor
<?php
//Load the Predis autoloader
require("Predis/autoload.php");
//Register all classes
Predis\Autoloader::register();
//Create a redis client to publish event
$redis = new Predis\Client(array(
"scheme" => "tcp",
"host" => "127.0.0.1",
"port" => 6379
));
//Publish the event
$redis->publish("mychannel", "Woooow there !!!");
?>
pusher.js
var app = require('express')();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var redis = require('redis');
server.listen(8080);
io.on("connection", function (socket) {
console.log("new client connected");
var redisClient = redis.createClient();
redisClient.subscribe('mychannel');
redisClient.on("message", function(channel, message) {
console.log("mew message in queue channel");
socket.emit("schannel", message);
});
socket.on('disconnect', function() {
redisClient.quit();
});
});
receiver.html
<!doctype html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2" >
<div id="messages" >ss</div>
</div>
</div>
</div>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="http://localhost:8080/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost:8080');
socket.on("schannel", function(message) {
$( "#messages" ).append( "<p>"+message+"</p>" );
console.log("tweet from", message);
console.log("contents:", message);
});
</script>
</body>
</html>
That's all. You are done....
You can monitor redis messages using following command
redis-cli monitor
Jan 31, 2018
Both php 7.0 and 5.6 on Ubuntu
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php5.6 php7.0
sudo a2dismod php5.6
sudo a2enmod php7.0
sudo service apache2 restart
Apr 27, 2015
Disabling errors
In plesk panel
error_reporting -> enter custom value->E_ALL & ~E_NOTICE | E_STRICT
E_NOTICE - undefined variable warning
E_STRICT - Calling non-static methods statically generates an E_STRICT level warning.
error_reporting -> enter custom value->E_ALL & ~E_NOTICE | E_STRICT
E_NOTICE - undefined variable warning
E_STRICT - Calling non-static methods statically generates an E_STRICT level warning.
Feb 25, 2015
session null after redirect with header
This is session saving problem and i could fix it giving permission to session storing directory.
Other things to check
Other things to check
- session_save_path('"your home directory path"/cgi-bin/tmp');
- check register_globals. It should be off.
- After the header redirect, end the current script using exit(); (Or can use session_write_close(); Or session_regenerate_id(true))
Subscribe to:
Posts (Atom)