Cron And Inserting Response Html


Have searched for the solution but haven’t found one that fits completely. I need a popup window to be shown in 30 seconds after user came to the site at first time. In that window will be a list of some categories from db.

After I will start a session for new user I want to create a new job in crontab with 30sec timeout. Then, in CronCommand class the categories will be retrieved from db and rendered:

public function run($args)


        $dataProvider=new CActiveDataProvider('Category');





                //js-code to open the dialog    

                if (!empty($_GET['asDialog']))

                    echo CHtml::script('js:bootbox.modal($("#id_category").html());');



But now I don’t know how to render this info into specific div. And also I assume that there is better way to achieve my goal and will be glad to hear some advice!

What’s the purpose of the 30 second timeout?

When user first come to site after 30 sec in popup-window he can choose categories to see only news from chosen categories in his feed. It’s a feature for non-registered users.

Now I realized that in function run($args){} there must be an ajax call with url category/index that will put the list of categories in the specific div.

Still be glad to see a better solution if there is.

You don’t have access to the user’s browser from your console command, so I’m not sure how you intend to output to any div.

Are you saying that the 30 second delay is supposed to prevent non-members from selecting a category in the first 30 seconds, in order to encourage them to become members?

In any case, you could probably store something in the user’s session when it’s first created with a timestamp stating when the category can be selected. You could poll the server with an ajax request every ten seconds until this timestamp is reached and return the relevant HTML content when it is. You can generate the content as part of a standard page request thereafter, so polling is no longer needed.

I don’t see any need for a console task for this.


Instead of polling every 10 seconds, you could set a javascript timeout to perform the ajax request after the remaining time from the current page request has elapsed.

Thanks, Keith!

Yes I’ve figured out about console “Console applications are mainly used to perform offline work needed by an online Web application, such as code generation, search index compiling, email sending, etc.”

I’ve also tought about that solution, but it will not work if user will go from front page to another before 30 seconds will pass. I want the popup-window to appear no matter what page user is currently seeing. The only criteria is 30 seconds. I mean, he first see front page and reads it for 10sec, then he goes to second page and see the popup in 20 seconds after the page is loaded. Is that real to make?

It will work, you just need to base the timeout on the amount of time remaining in the session variable. If they click a new page after 8 seconds, then the session variable will tell you that there are 22 seconds remaining, which you use as your javascript timeout. You should probably wait an extra second to make sure that the required time has definitely elapsed.

Much thanks, you helped me a lot!