Hosting & Domaining Forum

Hosting Discussion => Free Hosting Discussion => Topic started by: nickan on Jun 22, 2023, 06:52 AM

Title: Efficient xlsx price list generation using PhpSpreadsheet
Post by: nickan on Jun 22, 2023, 06:52 AM
I utilize the PhpSpreadsheet library to generate an xlsx price list from my mysql database. Each customer receives a unique price list with customized prices and items, both of which are determined by a mysql query and php programming. Considering that there are approximately 300,000 positions on each price list and that the task runs cron on a schedule, how can I accelerate the production of said lists?

To augment efficiency, I currently employ memcache; however, it has a max capacity of 1 gigabyte, which is insufficient for my purposes due to hosting restrictions.
Title: Re: Efficient xlsx price list generation using PhpSpreadsheet
Post by: hermenepoke on Jun 22, 2023, 08:31 AM
In my opinion, a universal method (irrespective of the library employed) would involve filling a single cell or a range.
To achieve this, one needs to create a range(s) in the database and then import it into Excel with just a few operations.

As per my experience, implementing this on large files can result in substantial performance gains, sometimes even by several orders of magnitude.
Title: Re: Efficient xlsx price list generation using PhpSpreadsheet
Post by: blazonbazaar on Jun 22, 2023, 10:18 AM
CSV format allows for easy transfer of data from databases to other applications, such as Excel. This allows users to view the data in its original format or make modifications to a pre-existing file quickly. Additionally, generating a CSV file is fast due to its text-based
Title: Re: Efficient xlsx price list generation using PhpSpreadsheet
Post by: Kickera on Jun 22, 2023, 11:49 AM
There is yet another hack available.

XLSX can be thought of as a collection of XML files compressed into a zip archive, which is the fundamental nature of this format.

XML processing is simpler in PHP compared to XLSX.

However, this process can be quite challenging as we need to understand the entire structure behind it. Nevertheless, it could be an engaging task to undertake.

As a note, understanding the underlying structure of file formats can be useful for data manipulation and analysis.
Title: Re: Efficient xlsx price list generation using PhpSpreadsheet
Post by: jahanzaibkhan on May 29, 2024, 11:33 AM
There are several approaches that can be used to accelerate the production of the unique price lists in your scenario.

1. Database Optimization:
  - Optimize database queries: Ensure that database queries are optimized by using appropriate indexes, avoiding unnecessary joins, and writing efficient SQL queries.
  - Database caching: Implement database query caching to store the results of frequently executed queries in memory, reducing the need to recompute the results for identical queries.
  - In-memory databases: Consider using in-memory databases like Redis to cache frequently accessed data, such as customer-specific price lists or common data used in generating the lists.

2. PHP Programming Optimization:
  - Code optimization: Review and optimize the PHP code responsible for generating the price lists. This includes ensuring that the code is efficient in data retrieval, processing, and formatting.
  - Utilize PHP caching mechanisms: Leverage PHP caching mechanisms such as OPCache or APC to store precompiled script bytecode in memory for faster execution.

3. Caching Solution:
  - Redis caching: Consider migrating from memcache to Redis, which offers higher capacity and more advanced features for caching data. Redis supports a wide range of data types and caching strategies that can be tailored to your specific use case.

4. Parallel Processing:
  - Parallelization of tasks: Implement parallel processing for generating price lists by using a job queue system such as Gearman or RabbitMQ. This allows for the distribution of the workload across multiple servers or processor cores, enabling concurrent processing of price list generation tasks.

5. File Generation Optimization:
  - PhpSpreadsheet optimization: Review the usage of the PhpSpreadsheet library and ensure that it is being utilized efficiently. Consider minimizing unnecessary data manipulation and optimizing the formatting and generation of the Excel files.