PHP - multi-thread jobs working with Google Cloud API - php

I created a Saas that collect orders from different websites for companies,
the websites are kind of "publishers" that provide the company orders every day.
I don't have an API so I'm scraping HTML from those websites by using the username and password that the company provides me.
After importing and saving the orders in my database, I'm sending them to the company's printer using Google cloud print API and the company working on the order in real-time.
After the order has been sent to print, I'm sending a post request to the website that basically clicking on a button that says "I got the order and I'm working on it", kind of accepting/approving the order.
the company has a UI that shows them a table of today's orders, for each order, they can see that the order has been approved and sent to the printer by google cloud print and they assume that the order was really printed.
So far, so good, but I have a big issue.
sometimes google cloud print doesn't recognize the printer and the company has to restart the computer that is connected to the printer, the issue is that my UI shows the user that the order has already been printed and also approving the order on the original website so the clients got an approvment that the company is working on the order right now.
google cloud print API provides me the option to check the status of the print but it takes about 6 seconds and maybe the status is "in progress" so it will take me more than 6 seconds for 1 order to get the status I wish for - "done".
right now I have a 2 cron jobs that run every minute,
the first is importing new orders and second sending new orders to print.
when I send an order to print it takes about 4 seconds, so i can send only up to 15 orders per minute, as I said the companies are working in real-time so I cant have any delay from the moment that the order appears in one of the websites to the moment it comes out the printer
I wish that i worked like that:
step 1:
import the order
step 2:
send it to the printer
step 3:
check the status
step 4:
approve the order on the website after I got a "done" status.
I think that my biggest issue is that it's not working with multi-threads
I'm looking for the best way to manage and work with multi-thread jobs in PHP.

Related

Cron-Job Issue with double Proccesses

We have a business, where we send API request to generate digital products. We have 2 jobs, one order based and one cron-job to process open orders.
I don't know where i should search the Problem.
Problem is;
the Cronjob double processed now 3 times (on 3 different days) products.
Example: Our Shop asks with a simple JSON POST the other system to get the Products by API. This is initiated by the Cronjob. The other System always makes, what the request incoming want.
If the Shop asks for 1 product, the system ordered two. Two similar requests are made to the API.
I don't know if this Problem is coming from;
the store (where the Cron Job Script is started)
the System
somewhere else
It is suspicious, that not the whole Job is done twice, it was only for some orders and some products. And not always. Does any one had a some Problem or a probably solution for that?
We already have some Security checks to prevent that, but it looks like it doesn't help. (The double processing is very bad, the products are like money (giftcards), if a customer get's to much of the digital cards and he redeem it immediatly, the money is lost).

Mailchimp API 3.0 How to retrieve statistics for an automation with a daterange

Hi I need to build a dashboard which shows stats for our automation campaigns such as sends, opens, bounces etc.
The Mailchimp api only returns for the entire period the automation has been active. I want to see the stats for a particulier date, however I can't find an API method that accepts a date range or groups results per date. The lists/activity method is exactly what I need, but it doesn't include e-mails sent using an automation :(
I have emailed the Mailchimp support team and they recommend me to use the /reports/email-activity method. This returns a long list of all open and bounce activities for an automation. I have tried to use this, but this is also not a good solution. This means I would have to store thousands of events in MySQL and run complicated group by and where queries to get my data. Furthermore this only includes the open, click and bounce events, thus this data is worthless without knowing how much e-mails were sent on the date of an event because you can't calculate open rates.
Does anyone know a way the retrieve stats for just one date? What I am looking for is a Mailchimp version of Mandrill method: https://mandrillapp.com/api/docs/messages.JSON.html#method=search-time-series.
Thank you for you time and help
for the campaigns exist "Response body parameters"
before_send_time
since_send_time
campaigns?since_send_time=2016-02-21T15:41:36+00:00&before_send_time=2017-03-10T15:41:36+00:00

How to make ChannelAdvisor send orders to my application?

I'm writing a php application which would do something with orders from ChannelAdvisor (CA).
Currently, I use CA API to get orders, and setup a cronjob which get orders from CA every minute, but this is not a good practice as my system need to process those orders in time. So, I'm finding a way to have my application receive CA orders right after placed.
In Shopify, they have webhook notification which would send json to a specific URL whenever an order was placed, is there something like that in CA?
Channeladvisor does not support webhooks or realtime notifications of any sort.
Scheduling an import (as you are) is as efficient as it will get.
Keep in mind that there are several delays before an order actually is served up for import.
It must first pass the marketplace's fraud checking, then channel advisors internal worker must import the order into their system, and finally your scheduler will pull in the order.
If you need timely orders it's best to connect directly to the marketplace and cut out the middleman.

Push notification for web application From one module to other module

i have integrated the notification system for web to android and Apple.
but now i have to integrate the notification system for web application part .
For ex.
currently i am working on restaurant project.
Now When customer Order From his / her mobile application on that time i have to show his/her order in Kitchen department . for that i have to Run ajax From kitchen department module to check that customer is ordered anything.
but the problem is when we run ajax every single minute then it will affect the server. because most of the server are not compatible ( for handling so many ajax request. ).
so i thought can we integrate the concept as same as push notification service for android and ios.
or anything else (different concept) for this one. please suggest a new idea.
i thought many option but at last time it will reach to the solution ajax request

How to realize a Newsletter system with Rss news feed?

I have a news portal with everyday news. My need is to send through newsletter the daily news to subscribers.
I've already realized a PHP/MySQL custom newsletter system that performs the following tasks:
fetches the daily news
fetches the list of users who want the newsletter
everynight through a cronjob I launch a script that performs the above every 5 minutes sending the newsletter to 10 recipients at a time each cycle
Problems:
I have to estimate how long this cronjob needs to run in order to complete the full list of users (5' x 10 emails) = 120Email/hours = TotalUsers/emailperhours = number of hours the cronjob needs to run
I overcome this problem because I don't have so much users until now and I can still manage to make the cronjob run enough to send all mails, but for the future?
All email receievers are saved double opt-in, means I'm quite sure of their existence, but it happens how you can imagine that I'll have anyway many Mail delivery for other reasons:
here I need help because I dunno how to catch there Mail delivery through PHP and update MySQL tables in order to suspend these unnnecessary sendings.
Alternatives:
I know that there are many providers who offer Newsletter systems but this works fine every time u go and compile your static email body. Here I need a dynamic email body to be generated every day with fresh news and then send it to recipients.
Still here I need some advice.
You might find it worthwhile using a service like SendGrid - they have an API that handles dynamic content. I haven't tested it out that aspect myself, but for the small price they charge it might be worth saving you the headache.

Categories