I am trying to change the number automatically after every five seconds between 1 to 90.
Here is my code,
public function getNumber(Request $request)
{
$numbers = rand(1, 90);
$data = array('message'=>ResponseMessage::statusResponses(ResponseMessage::_STATUS_DATA_FOUND), 'number'=>$numbers);
return $this->sendSuccessResponse($data);
}
Now, when I hit this I am getting the number between 1 to 90. I am getting different numbers whenever I hit.
But now, I just want that, when I hit it. It will start and after every 5 seconds number will change automatically.
Can we do that, if yes, please help me out. Thanks in advance.
you can use javascript for this and call your function or send ajax rewuest to your controller there:
window.setInterval(function(){
/// call your function here
}, 5000);
it will run every 5 secs
and for stop that :
clearInterval()
Related
For this question which of the session or cookie will do the desired job ?
I'm intrigued by the results after triggering a $_Session because I thought it only triggered when a visitor accessed the website.
In one day I had 378 accesses to my website or to the server that hosts my website. The whole world is trying to access my website while it is not online (12 countries). But that is not the problem at all!
In less than 30 min there were 20 new visits from 6 different countries. Is it normal ?
Why are these accesses to my website counted when the statistics collected by my host only give me the reloads of pages that I perform (about 14)?
Does the Host already filter bot ?
But that doesn't explain why I get about 200 results from my own ip address when I deleted all windows to my website between tonight and this morning .
Also the increment is multiplied by two instead of being incremented by 1 .
How can I count the number of anonymous visitors every 24 hours who access my website?
Can I limit the duration of a session to 10 seconds ? Does this restriction can filter bots ?
I try to store in one row of specific table :
the auto-increment Id
the unix time of day
the number of visit incremented each time.
for now that's all I need.
Currently the main problem is the increment $_SESSION thats increment by 2 instead of 1 :
function StartSession(){
global $wpdb;
session_set_cookie_params(0, '/', '.website.com');
session_start();
if ( !isset( $_SESSION['visitor'] ) ) {
$countuser = $_SESSION['visitor'] = 1;
}else{
$countuser = ++$_SESSION['visitor'];
}
$users_analytics = $wpdb->prefix . 'antics_users';
$timeanonymesession = time();
$wpdb->insert(
$users_analytics,
array(
'datesession' => $timeanonymesession,
'totalusers' => $countuser
//'iploc' => $new_ip
)
);}
add_action('init', 'StartSession', 1);
If I use a cookie instead of a session, I think I'll have the same problem with incrementing, right?
Edit : in one day the *_SESSION have registered in database more than 1500 visit.
I don't understand why I have so many connection with $_SESSION whereas My Host registered only between 10 and 15 sessions by day (that normally corresponding to my reload page during developpement) ?
I am Trying to subtract 1 minute from duration column through update query but it is not working. Duration field is of type time.
I try to use minus sign with new value but it is not working.
public function index()
{
$current = Carbon::now('Asia/Karachi');
Sale::where('date','=',$current->toDateString())
->where('time','<=',$current->toTimeString())
->update(['duration' => '- 00:01:00']);
}
I want to subtract one minute with help of this query.
Can you use DATE_SUB?
Something like
$object->update(['duration' => DB::raw('DATE_SUB(duration, INTERVAL 1 MINUTE)')])
I don't have a laravel instance in front of my, but that's how I'd write the SQL query and I think that's right based off my laravel memory.
Given an Observable.timer(10000). Say, that I'd like to continuously update the timer and not allow it to emit, is it possible?
For example, at t = 2000, I want to increase the timeout time by 2000. Given this dynamic code change, the timer will now emit at t = 12000 rather than the original t = 10000.
try the code below.
Rx.Observable.fromEvent(document,"click")
.scan((curr,acc)=>++curr,0)
.flatMap(e=>{
console.log(e)
return Rx.Observable.timer(e*1000)}
)
.subscribe(console.log)
Possible to somehow limit the update download 0.3 seconds using a ReactiveCocoa?
example:
if (the_previous_update == indefinitely)
{
update;
}
if else (current_time - the_previous_update>=0.3)
{
the_previous_update = current_time;
update;
}
else{
do nothing;
}
Maybe something like this?
RACSignal *updateSignal = ... // a signal that sends a 'next' whenever download has progressed.
[[updateSignal throttle:0.3] subscribeNext:^(id x) {
updateUI();
}];
Yes as #Grav says a throttle seems like the best operation for your use case. A throttle will basically store up next events and dispatch the last one received within your given time interval.
With a throttle you can make sure that you can update your UI every 0.3 seconds and be sure that the value that you use to update will be the last one received in that given time interval.
This differs from delay.
I have a BIRT report that displays some statistics of calls to a certain line on certain days. Now I have to add a new measeure called "call handling time". The data is collected from a MySQL DB:
TIME_FORMAT(SEC_TO_TIME(some calculations on the duration of calls in seconds),'%i:%s') AS "CHT"
I fail to display the duration in my crosstab in a "mm:ss"-format even when not converting to String. I can display the seconds by not converting them to a time/string but that's not very human readable.
Also I am supposed to add a "grand total" which calculates the average over all days. No problem when using seconds but I have no idea how to do that in a time format.
Which data types/functoins/expressions/settings do I have to use in the query, Data Cube definition and the cross tab cell to make it work?
Time format is not a duration measure, it cannot be summarized or used for an average. A solution is to keep "seconds" as measure in the datacube to compute aggregations, and create a derived measure for display.
In your datacube, select this "seconds" measure and click "add" to create a derived measure. I would use BIRT math functions to build this expression:
BirtMath.round(measure["seconds"]/60)+":"+BirtMath.mod(measure["seconds"],60)
Here are some things to watch out for: seconds are displayed as single digit values (if <10). The "seconds" values this is based on is not an integer, so I needed another round() for the seconds as well, which resulted in seconds sometimes being "60".
So I had to introduce some more JavaScript conditions to display the correct formatting, including not displaying at all if "0:00".
For the "totals" column I used the summary total of the seconds value and did the exact same thing as below.
This is the actual script I ended up using:
if (measure["seconds"] > 0)
{
var seconds = BirtMath.round(BirtMath.mod(measure["seconds"],60));
var minutes = BirtMath.round(measure["seconds"]/60);
if(seconds == 60)
{
seconds = 0;
}
if (seconds < 10)
{
minutes + ":0" + seconds;
}
else
{
minutes + ":" + seconds;
}
}