Running background process in LAMP stack - php

I have an application running on LAMP stack.In USER model
after expiration of subscription deadline,I need to set user's current
subscription to default or free subscription.
So I need a background process which always checks for the expiration of user's subscription deadline and set to default subscription.
Is there any other efficient and manageable solution to run a background process which will update user's data ?
Application Environment:
CakePHP,Redis,MariaDB
Please edit if this question isn't good enough to describe my problem :(

So in general your question about recurring event,
if this event do changes in DB and also another actions like send emails or stop some services or connect to remote resource,, you have to use cron job
but if this event only related to DB then you can create recurring event like the following link

In case of PHP there is not so many out-of-the-box solutions. One of the available is rabbitmq-delayed-sample. It is built on top of rabbitmq messaging system.
Usage example:
$container->get('delayed_producer')->delayedPublish(5000, $messageBody, '');
where 5000 is an expiration period after that job will be executed. You can put such code to the new user creation place.

Related

Update expiration time of a google push notification channel

I am currently developing a web API where I need to listen for Google Calendar updates. I have therefor implemented the google push notifications for PHP following the documentation and everything works fine (Receiving notifications).
The problem I have is that I would like to update the channel expiration time so I don't have to create a new one every time. That is a waste of GPU and API requests, because as the documentation indicates, every time you create a new channel you start with a full initial sync (Synchronize Resources Efficiently) .
Instead, I would like to always make incremental synchronization. Any ideas on how to update the "expiration" field ?
Answer:
You cannot update the channel expiration time, you have to create a new one.
Reference:
From the link you provided, Renewing notification channels:
Currently there is no automatic way to renew a notification channel. When a channel is close to its expiration, you must create a new one by calling the watch method.
Related:
Provide a mechanism to renew activities.watch instead of erroring on non-unique channels

How to implement SSE (Server-Sent Events) in PHP Laravel

I am new to PHP Laravel. I have little bit confuse to build SSE in PHP Laravel. I searched around 1 day. but I didn't find any good resources to meet my requirements. Helps and other reference will appreciate
Suggestions
- I have different RabbitMQ queues to listen status of the message.If a new event occurs need
to update the blade(Have different blades included in my page. need to update only one of them).
if you doesn't understand my requirement:
I am looking for I chat system. I need to trigger the status in to my blade. the status will comes in rabbitMQ I need to take the status from there and change in browser. Eg:- If I sent message status will be in wait state. if the message get processed a new event will trigger in the queue I need to pick that status and update in browser this is exact my requirement

Best option to send email notification in advance for account expiration

I am working on a e-commerce kind of application which allows user to login register and also create a deal for him.
Every deal of the user has a expiry date attached to it.Now I store all the values in the DB table against the created deal.
I want to send the user a notification couple of days before his deal expires if he has not
updated it.Now can I achieve it using the DB trigger in any way(write a script and return value from the DB trigger) as suggested in this thread.
I should run a cron job to check it for some time interval and send notification?
I am not sure FB or other sites do it for birthday reminders or other notification.Any details on the same would be helpful to go ahead.
Thank you

How shall I setup user event notifications in my code?

I'm coding a team collaboration web app in PHP, and I have a few events that users get notified about through email and/or SMS. The current way I'm doing it is as follows:
Every user has his notification settings in the database as boolean variables.
Say users would be notified when someone comments on the team's page. When the function that posts a comment is called, the same function would contain extra code that checks "who wants to be notified about this?" and then sends notifications to them (which slows down the function a bit).
Is there a more efficient/faster/flexible way to setup notifications? maybe through a script that runs via a cron job? or shall I just keep doing it this way?
I appreciate your help.
I implemented a similar method to the one you're following on a website with a multi-table approach. The users table held the contact information along with opt-in, opt-out options while an event table held the instructions to notify. Several other events were hard coded because of their importance. The thing that set the site apart a bit was a "workflow" area on the user's dashboard that also showed the user what action items they had. We found that most users ignored the emails and dealt directly with that dashboard workflow area. You'd be surprised how many times people change emails or just ignore them altogether.
With 280,000 users and daily visits in the tens of thousands, there was no performance issue noticed. However, the process of queuing emails can be inefficient if you're not careful, so take particular time to benchmark your mail sending functions--its as easy as echoing out microtime before and after the mail send is accomplished--to evaluate its effectiveness. On my current company's site, such improvements yielded a 800% reduction of email queuing time (queuing being the process of generating the emails and submitting them via php mailer to the mail system for distribution)
I'd say have a table that is a queue of notifications. Let the function that post a comment still check "who wants to be notified about this?" but then just log entries containing the messages in this table. Then have a separate process work from the queue i.e. your cron job suggestion.
Depending on your database you may perhaps make use of database events or triggers instead of a cron job. This however have the requirement that your database allow you to put code in your database that will send the SMS or Email. This poses a security risk normally which you may or may not be concerned about in your setup.

Running a background process on an ecommerce website

I have programmed in C/C++, but I have no experience in web programming. Someone asked me to help them build a e-commerce website selling a service. I started looking into using PHP/MySQL for building the site.
My question is: given that HTTP is stateless, how do we get some background process to trigger so that it may, for instance, gather the list of customers and then send an email with the list in it to some known email address? I want this task to run, say every day at a set time, and not only when a user accesses or performs some action on the site.
You will want to use a cron job.
My favorite tutorial: http://www.unixgeeks.org/security/newbie/unix/cron-1.html
Cron job?
Maybe this will help: http://www.thesitewizard.com/general/set-cron-job.shtml

Categories