Skeletor
Skeletor

Reputation: 3403

Is there a way to (manage) add milliseconds ( to now() ) in laravel?

I want to add milliseconds to delay jobs in laravel queue. We can add seconds like:

SaveJob::dispatch($data)->delay( now()->addSeconds(1) );

But I need to add milliseconds. I didn't come across such a method in the Carbon library. But to get some ideas I wanted to ask anyway.

Upvotes: 3

Views: 1041

Answers (1)

Skywarth
Skywarth

Reputation: 813

pratical alternative: usleep - Delay execution in microseconds

To sleep for two miliseconds:

usleep( 2 * 1000 );

So in your case, can you please try:

SaveJob::dispatch($data)->delay( now()->usleep( 2 * 1000 ) );

or

SaveJob::dispatch($data)->delay( usleep( 2 * 1000 ) );

Upvotes: 1

Related Questions