I am working on a project that manages employee payrolls using php (no frameworks). This application consists of clients (with their own databases). Each database consists of the client's employees and their payrolls. The relevant features are:
- An administrator can process a payslip twice a month for all employees in a particular client. When clicking a "process" button, a pdf file will be created for each employee and stored in a directory.
- And administrator can select employees in a table of employees for a particular client, then send each selected employees an email containing their pdf file when a button is clicked. The pdf file is different for each employee.
- And administrator can select clients in a table of clientss, then for each client, send all employees an email containing their pdf file when a button is clicked. The pdf file is different for each employee.
My initial solution for creating pdfs and sending emails is to iterate through the list of employees retrieved from each client database and perform some action when a button is clicked. However, when I select 40 employees to create pdf files for them using fpdf, the application took 4 seconds to finnish. This is unacceptable because each client might contain at most 5000 employees. Same goes with sending emails using phpmailer, it took 25 seconds to send three emails.
So, I started looking for a multithreaded solution where each action could be executed at the same time. However, pthreads v3 only works in CLI, we are using php 7. I don't know about using multiple processes, but I've read it could be complecated.
Is there a viable and fast solution to achieve what I want in php? Should I use a different language?