I am using Laravel 8 my cookie function not create cookie in browser. My code is
public function connectWoocommerce(Request $request)
{
Cookie::queue('site_url', $request->site_url, time() + (10 * 365 * 24 * 60 * 60));
Cookie::queue('key', $request->consumer_key, time() + (10 * 365 * 24 * 60 * 60));
Cookie::queue('secret', $request->consumer_secret, time() + (10 * 365 * 24 * 60 * 60));
dd($request->all());
}
How can solve it thanks.
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class middleware is responsible for setting queued cookies to the response. Make sure to have it in you $middleware list.
It will not be called if you terminate the script from anywhere within your controller.
Related
Is it possible to set lifetime for doctrine result and query cache globally (not second level cache). I do not want do it for every query, like below:
$queryBuilder
->getQuery()
->useResultCache(true)
->setQueryCacheLifetime(7 * 24 * 60 * 60)
->setResultCacheLifetime(7 * 24 * 60 * 60)
->getSingleScalarResult()
I have a Spring app with this property:
cobra.tarifas.intervaloEntreCobrancas =*/37 * * * * *
And this is where it's used:
#Scheduled(cron = "${cobra.tarifas.intervaloEntreCobrancas}")
public void cobraTarifaDMaisZero() {
int number = new Random().nextInt();
System.out.println("started " + number + " at " + LocalTime.now().withNano(0));
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("finished " + number + " at " + LocalTime.now().withNano(0));
}
So every time it runs I have a log that points out when it started and finished, along with a "unique" identifier (Spring uses same instance at #Scheduled classes with no extra configuration, this.toString returned same string everytime). Every execution takes 5 seconds to complete.
I thought that cron expression meant "runs everytime every 37 seconds" but it didn't.
Using * * * * * * I got this:
started -1615036471 at 10:18:46
finished -1615036471 at 10:18:51
started 2090620070 at 10:18:52
finished 2090620070 at 10:18:57
started -349207943 at 10:18:58
finished -349207943 at 10:19:03
Which made sense: it takes 1s to start a new execution after a previous one was finished, always taking 5s to complete. But when I used */37 * * * * * I got
started -644623959 at 10:54
finished -644623959 at 10:54:05
started 212117957 at 10:54:37
finished 212117957 at 10:54:42
started 1788724609 at 10:55
finished 1788724609 at 10:55:05
started 362510867 at 10:55:37
finished 362510867 at 10:55:42
started -25103618 at 10:56
finished -25103618 at 10:56:05
started -820939074 at 10:56:37
finished -820939074 at 10:56:42
Why it's starting only at seconds 00 and 37? I wanted to implement a similar behavior as Spring's #fixedDelay but flexible to be changed at some properties file(#fixedDelay only accept constants).
I don't think that you can actually do this only with cron, for a number such as 37.
The easiest option, would be to select an increment that can divide 60.
Basically an even number that is equal to ( or less than) 30.
E.g. So 10, 15, 20, or 30.
For 10, your expression would be:
cobra.tarifas.intervaloEntreCobrancas =0,10,20,30,40,50 * * * * *
Otherwise, you could just go for once per minute.
0 * * * * *
I want to set a timer at 9:00 / 16:30. But one cron can not realize it.
So i need two cron to realize it. The corn is as follows:
cron1: * 30 16 * * *
cron2: * * 9 * * *
I want to set cron by springboot #Schedule like this
#Scheduled(cron = "0 0 2 * * ?")
public void sayHello(){}
But it seems that can not support two #Scheduled label on one method or two cron in one label.
The so low method is as follow, Any better advice?
#Scheduled(cron = "* 30 16 * * ?")
public void sayHello(){}
#Scheduled(cron = "* * 9 * * ?")
public void subSayHello(){sayHello();}
I think it is difficult because of the different min and different hour,
if the cron run in the same hour or min, it will be easy.
Such as:
"* 0,30 9 * * ?"
"* 0 9,16 * * ?"
Or you can see this link Cron expression to run job twice a day at different time?
Spring Boot here. I have a scheduled background task that I kick off every hour on the hour:
#Component
public class TokenReaper {
#Scheduled(cron = "0 0 * * * *")
public void fire() {
// Doesn't matter what it does...
}
}
I actually need it to now run only at 8:26 AM every day, so only once a day at that time (strange, I know!), so I change the cron expression to:
#Component
public class TokenReaper {
#Scheduled(cron = "0 26 8 * * *")
public void fire() {
// Doesn't matter what it does...
}
}
After making this change, the task stops running at 8:26 AM, and because of the logs I can't tell when its actually running or if its actually running at all! Can anyone see if my new cron expression is somehow malformed or not correctly set to run at 8:26 AM each and every morning?!
You need to add ? in your cron expression by:
Changing #Scheduled(cron = "0 26 8 * * *") into:
#Scheduled(cron = "0 26 8 * * ?")
Try this
#Scheduled(cron = "0 26 8 * * ?")
Cron expression is represented by six fields:
second, minute, hour, day of month, month, day(s) of week
Example patterns
* "0 0 * * * *" = the top of every hour of every day.
* "*/10 * * * * *" = every ten seconds.
* "0 0 8-10 * * *" = 8, 9 and 10 o'clock of every day.
* "0 0 8,10 * * *" = 8 and 10 o'clock of every day.
* "0 0/30 8-10 * * *" = 8:00, 8:30, 9:00, 9:30 and 10 o'clock every day.
* "0 0 9-17 * * MON-FRI" = on the hour nine-to-five weekdays
* "0 0 0 25 12 ?" = every Christmas Day at midnight
now I have this configuration my my scheduler:
<task:scheduled ref="task" method="run" cron="0 45 22 * * *" />
when this task is executed ? and how I can change it to do this task every minute
This task is executed at 22:45:00 every day, every week, every month.
To execute a task every minute, use
0 * * * * *
The accepted answer is correct for spring. Other than that, one should be careful whether the target system uses 6 or 5-digits cron.
With 5-digits-crons
0 * * * * schedules to be run "at minute 0" (hence every hour).
The correct answer in this case should be either
* * * * *
or
*/1 * * * *
Also see: Spring cron vs normal cron?