Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make phpodt work in a parallel environment #36

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

sboden
Copy link

@sboden sboden commented Dec 14, 2022

First up: the composer changes can be reverted of course.

cybermonde/phpodt overwrites data in a parallel execution setting, and this pull request fixes that.

We were using phpodt as a templating engine to created ODT letters to be converted by jodconverter to PDF. It's part of a Drupal application that sends about 50.000 letters per day. Generating a letter from beginning to end took 5 seconds, so we executed the creation of letters in parallel (about 15 threads creating them). What we noticed after a couple of weeks is that some people received the letter of another person (about 1 in 15.000).

We investigated and came to the conclusion that cybermonde/phpodt is not suited to run in parallel, in particular when you use PclZipProxy: both phpodt and pcl.zip.lib make some wrong assumptions about "unique" output locations. We mitigated the problem by extracting the text from the final pdf, comparing the text to the document number we were printing for, and ignoring/retrying the output when they differed.

The detail root cause: phpodt used uniq() to get a unique temp filename. Unfortunately uniq() is only a kind of hex representation of the current time so sometimes it returns the same value in different threads causing data overwrites. The pcl.zip.lib library included does the same in a couple of places.
If you only have 1 thread creating letters than the current cybermonde/phpodt should be fine.

This pull request are all the changes I made to make phpodt able to run in parallel without problems. I did not change the existing interfaces. The sboden/phpodt (2.2.1) of this pull request code has been running for about a week in production, so after +-300,000 letters no overwritten printouts were detected anymore.

wfr,
Sven

@cybermonde
Copy link
Owner

Thanks for keeping this project alive, sorry I don't have time to improve it anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants