How to display server clock to the user using laravel 5.2 - laravel-5

I have been assigned a task to display server clock to the user. I can do that using jquery, but we need to display our server clock which will be like a clock.
Like i have date format like : 2016-06-30 10:27:32 and it should be updated like a timer or a clock is running. I have search a lot on internet, but i did not get any clue.
Please suggest me the solution.

Probably the best solution is to get time/date from server and increment it via jquery/JS.
<?php $currentTime = getdate(); ?>
<script>
var date = new Date(Date.UTC(<?php echo $currentTime['year'] .",".
$currentTime['mon'] .",".
$currentTime['mday'] .",".
$currentTime['hours'] .",".
$currentTime['minutes'] .",".
$currentTime['seconds']; ?>));
setInterval(function() {
date.setSeconds(date.getSeconds() + 1);
console.log((date.getHours() +':' + date.getMinutes() + ':' + date.getSeconds() ));
}, 1000);
</script>
Because setInterval isn't the most precise function, you should probably update your date once per minute via AJAX request.

Related

Laravel broadcast()->toOthers() methods does not work, still getting duplicates (Laravel 8 / Pusher / Laravel Echo / VueJs 3

I am listenig for MessageSentEvent
window.Echo.private("chat" + this.chat.id).listen(
"MessageSentEvent",
e => {
var date = new Date().getTime();
this.lastMessageDate = moment().to(date);
this.lastMessage = e.message;
console.log(e.message.sender.id, this.loggedInUser.id);
// if (e.message.sender.id !== this.loggedInUser.id)
this.chat.messages.push(e.message);
}
);
while I am using the toOthers-method in my controller
broadcast(
new MessageSentEvent(new MessageResource($message), $authUser)
)->toOthers();
leading to duplicates for the one who sent the message
duplicates for the sender
while the receiver just get the expected 1 message
receiver as expected 1 message
if using the outcommented condition, it works fine.... but too me it does not feel clean.
I must have made a mistake somewhere. Why does the toOthers()-method not work and I need to write a condition?
Thx:)
On your axios config try to add your connection socket id.
Try this if You use Echo and if You use pusher or any socket library run the function that return a scketId :
window.axios.defaults.headers.common['X-Socket-Id'] = window.Echo.socketId();

Hyperledger composer performance(adding asset) is very low

Following code is simple code to check how many entities can be added per second or minute.
createAsset is calling backend(http:localhost:3000) and add data using post.
When I did test using this code, it took 23 seconds to add 10 entities.
I am using composer 0.19.12 and fabric 1.1. When I checked some thread from GitHub, performance has improved using indexing couchdb. How can I use that feature? (I need to check again, but it seems that it is default feature of recent composer version)
addEntities: async function() {
var start = 0;
var end = start + 100;
var sd = new Date();
console.log(sd.getHours()+':'+sd.getMinutes()+':'+sd.getSeconds()+'.'+sd.getMilliseconds());
for(var i = start; i<end; i++) {
entityData.id = i.toString();
await this.createAsset('/Entity', 'model.Entity', entityData);
}
var ed = new Date();
var totalTime = new Date(ed.getTime()-sd.getTime());
console.log(totalTime.getMinutes()+':'+totalTime.getSeconds()+'.'+totalTime.getMilliseconds());
},
My model is really simple as follows.
asset Entity identified by id {
o String id
}
I have changed the test code to send multiple transactions as follows following david_k's advice.
addEntities: async function() {
var start = 15000;
var dataNumber = 1200;
var loopNumber = 400;
var end = start + dataNumber;
var sd = new Date();
console.log(sd.getHours()+':'+sd.getMinutes()+':'+sd.getSeconds()+'.'+sd.getMilliseconds());
var tasks = [];
for(var i = start; i<end; i++) {
entityData.id = i.toString();
if((i-start)%loopNumber === loopNumber - 1) {
await this.createAsset('/Entity', 'model.Entity', entityData);
console.log('--- i: ' + i + ' loops completed');
}
else {
this.createAsset('/Entity', 'model.Entity', entityData);
}
}
var ed = new Date();
var totalTime = new Date(ed.getTime()-sd.getTime());
console.log(totalTime.getMinutes()+':'+totalTime.getSeconds()+'.'+totalTime.getMilliseconds());
},
The purpose of change is send multiple requests at the same time, and it seems work well because it shows much better performance compared to previous code. However, the performance is still around 8 TPS. As original test code was 1 transaction per 2sec~3sec, it improved a lot. But, 8TPS looks that it cannot be used for commercial application at all. Even it is not good for test purpose as well. Could someone give some advice for this?
That sounds about right looking at your example code and I am assuming you are using either the fabric-dev-servers package which is a very simple fabric network to help get users started with developing a business network and want to try out on a hyperledger fabric network, or you are using the byfn network from the multi-org tutorial which is a hyperledger fabric example of a 2 organisation network in a consortium to demonstrate the required operational steps of composer in a multi-org fabric setup.
Hyperledger Fabric is a distributed ledger technology based around eventual consistency. Composer implements a submit/notify model such that once a transaction has been submitted it will notify the client when that transaction has been committed to the ledger. You can configure which Peers in a network you are interested in informing you when that occurs, but the default is all of them and so the rest server responds once all peers have committed it to the ledger.
Hyperledger fabric doesn't commit individual transactions, it batches them up into blocks and these blocks get committed to the ledger, and it will wait a period of time before building that block with the current set of transactions that have been submitted for ordering, so blocks can contain one or more transactions. You need to configure fabric for your use case to determine how transactions are batched into blocks.

php - i am getting logged out after being idle

I do not want the user to be logged out of the site even if the person is idle for, it is okay if the person is logged out if he has closed the browser.
session.gc_maxlifetime = 180000
session.gc_probability = 1
session.gc_divisor = 1
session.save_path = "/var/lib/php/session"
cookie_lifetime = 0
Is there any setting that i am missing?
Please help
To set the life time i have added the following code.
session_set_cookie_params(21600);
session_start();
You need extend your live time of cookie, remember that session id is stored in user webbrowser within cookie, set session.cookie_lifetime with a more big value too.
session_set_cookie_params(21600);
session_start();
21600 seconds is only 6 hours
Try setting to something bigger maybe even PHP_INT_MAX
Dont know whether it will help just wrote to give u the idea of how?....cookie are saved at user browser so ,
$cookieName = "userscookie";
$lifetime = time() + (60*60*24); // one day life
if(isset($_COOKIE[$cookieName])) {
$value = $_COOKIE[$cookieName];
// one day life from day of access
setcookie($cookieName, $value, $lifetime);
} else {
$value = "this value to store";
setcookie($cookieName, $value, $lifetime);
}
output:
Thankyou

Is measuring js execution time a way to tell how quickly the app is responding to requests?

I have something like a microtime() function at the very start of my node.js / express app.
function microtime (get_as_float) {
// Returns either a string or a float containing the current time in seconds and microseconds
//
// version: 1109.2015
// discuss at: http://phpjs.org/functions/microtime
// + original by: Paulo Freitas
// * example 1: timeStamp = microtime(true);
// * results 1: timeStamp > 1000000000 && timeStamp < 2000000000
var now = new Date().getTime() / 1000;
var s = parseInt(now, 10);
return (get_as_float) ? now : (Math.round((now - s) * 1000) / 1000) + ' ' + s;
}
The code of the actual app looks something like this:
application.post('/', function(request, response) {
t1 = microtime(true);
//code
//code
response.send(something);
console.log("Time elapsed: " + (microtime(true) - t1));
}
Time elapsed: 0.00599980354309082
My question is, does this mean that from the time a POST request hits the server to the time a response is sent out is give or take ~0.005s?
I've measured it client-side but my internet is pretty slow so I think there's some lag that has nothing to do with the application itself. What's a quick and easy way to check how quickly the requests are being processed?
Shameless plug here. I've written an agent that tracks the time usage for every Express request.
http://blog.notifymode.com/blog/2012/07/17/profiling-express-web-framwork-with-notifymode/
In fact when I first started writing the agent, I took the same approach. But I soon realized that it is not accurate. My implementation tracks the time difference between request and the response by substituting the Express router. That allowed me to add tracker functions. Feel free to give it a try.

ajax get xmlHttpRequest load time

Is there a way to get an xmlHttpRequest load time?
Otherwise I'll have to set a function that count it, so?
To the best of my knowledge there isn't an execution time included as part of the XMLHTTPRequest object. You can, however, use JS to calculate this value:
const start = Date.now();
// Execute request
alert( "Request took: " + ( Date.now() - start ) );
For more info on the data that is stored in the XMLHTTPRequest object, see this page.

Resources