Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
In this tutorial, to run two consumers, I open two consoles and type php worker.php into each.
https://www.rabbitmq.com/tutorials/tutorial-two-php.html
Instead I want to create some workers when a user logs in, and destroy those workers, when logging out. Is this possible within the php framework, If not what route might I take using bash scripts or similar?
[edit: more info]
Under normal circumstance I might spin up a few workers to do some tasks that take a long time. For my website I would like up to eight identical workers for every logged in user. Destroying the workers after use is no so much an issue. But If I spin up 16 workers(for two concurrent users) and a third person logs into my website I would like another 8 workers to be initiated.
I could check the logs each day, find out what was the max concurrent users and spin up the required number manually, but I'm assuming there is a better way.
The answer is: Yes, it is possible. The best solution depends on the project details.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a case where the user wants to be able to add Jobs using the UI, and he should be able to start and stop them at any given time.
So the jobs should be added dynamically at the run time, how can I achieve this functionality with laravel?
You may want to check out the laravel-dynamic-scheduler package. Even if you don't use the package it still can serve as a nice code example for you.
You essentially create a proxy task, and then through that task, can dynamically call other tasks created by users. The proxy task can check a database table of tasks you can have user's manage.
It is essentially using the same method Laravel itself does in the scheduler, as the scheduler itself is really just a proxy for the system's Cron.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I created table account here 5 columns a/c_no date, deposit withdraw balance. I need to insert data automatic after 2 days with date and value of interest. How to code this?
For this you have make a scheduler kind of thing, that runs on scheduled time and do the assigned task with the specified logic. In linux, cron is there for this purpose.
Cron Jobs are used for scheduling tasks to run on the server. They're
most commonly used for automating system maintenance or
administration. However, they are also relevant to web application
development. There are many situations when a web application may need
certain tasks to run periodically. Today we are going to explore the
fundamentals of Cron Jobs.
Reference
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a start_processing("set 1") function which takes 6 hrs to complete set1,
I want to process set 2, set 3 .... how can i process all of them in same time ?? since when i put
<?php
start_processing("set1");
start_processing("set2");
start_processing("set3");
?>
It takes 18 hrs.
I want to complete process in 6hrs for all processing.
Finally i got a solution
I have take curl_multi - it is far better. Save the handshakes - they are not needed every time!
Use curl_multi_init to run the processes in parallel. This can have a tremendous effect.
Unless you are using PHP as Apache-module, you can use pcntl_fork to create several processes of which each processes one function call.
if(pcntl_fork())
start_processing("set1");
else if(pcntl_fork())
start_processing("set2");
else
start_processing("set3");
If you have a varying number of working sets, just put them in an array and loop through it. Just bear in mind that too many processes could overload your system!
Another, more lightweight, option is the use of php pthreads which AFAIK work with Apache, but require installing the corresponding php-extension first.
A third possibility is, as mentioned by sandeep_kosta and Niranjan N Raju, to create one Cronjob for each working set.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am wondering if there is a way to add a new user automatically in a mysql table every minute or so ?
I have a USER table and a USER ACTIVE table, when ever a user is active the details goes under the USER ACTIVE table. I would like to automatically be able to add and delete x number of users from the USER ACTIVE table every minute.
How do I achieve this? I am also a beginner with PHP (which is what I am using) MySQL.
You can't do what you want in pure PHP. PHP is designed to render a page on request and then finish, it won't keep running with a timer. You can either set up a cron job as Dagon suggests, or look at adding some java or similar that keeps running a timer once the page is loaded - which I don't think you want, because that would still require the page to be open somewhere.
I have something similar set up using only PHP, the cron job simply launches the PHP interpreter to run the page every so often: "php /home/user/timer.php". Exactly how you set this up is going to depend on what level of access you have to the system and what commands are available, but most web hosts will allow the setup of a basic cron job.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to run a php function on my server in a certain time without make the script sleep.
I need this in order to update my database in specific time.
For example a chat room that lasts for 5 minutes.
The chat room have a flag in the database for open status.
I want to change the flag in the database to close after 5 minutes.
public function callOnDelay($time, $data)
{
//SOME CODE EXECUTED AFTER SOME TIME IS OVER//
}
There are different ways of doing this depending on your OS.
On Linux you can look for Cron Jobs (http://www.thesitewizard.com/general/set-cron-job.shtml).
On Windows you can look for Task Scheduler (http://technet.microsoft.com/en-us/library/cc766428.aspx).
Also another, not so reliable, method of doing this is adding a conditional/if in your main script (index.php ?) or a "before function" in your controller (if you are using some kind of framework that supports it) and checking for the last status and doing something with it.