I
I
ipadm2013-06-21 15:56:33
PHP
ipadm, 2013-06-21 15:56:33

IIS, php, w3wp.exe, cmd.exe and multithreading? to force not to stick processes?

Habrasoobshchestu Habraprivet!
There was a problem in the implementation of a fairly simple task. On the site, PDF is generated from PHP from various files, including those created on the fly using TCPDF. All these files are combined in a different order and sent to different mailboxes. Merge operations are performed via the passthru() call to PDFTK.
Everything works great if you call (refer to the page) once.
But if two or more users access the page at the same time, the cmd.exe process sticks and does not complete its work. More precisely, it does everything it should, but it simply does not complete and hangs in memory, preventing the PHP script from continuing to execute. Thus, several processes can stick in memory:
w3wp.exe
cmd.exe
pdftk.exe
cmd.exe
pdftk.exe
cmd.exe
pdftk.exe
cmd.exe
pdftk.exe
cmd.exe
pdftk.exe
...
cmd.exe
pdftk.exe
can only be killed by killing the w3wp.exe process. Such picture is observed only in Windows (specifically Win2003k server). Under Linux, the same script is executed with a load of up to 100 simultaneous calls without problems (I did not try the load anymore, because it is no longer expected by the technical specification).
Unfortunately, I'm stuck with using PDFTK. pure PHP classes that would not kill links inside PDF could not be found.
Please help with any advice.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Altimar, 2013-06-21
@Altimar

If you don't mind that the PDF will have a letter P in the corner of the first page (which is not visible when printed) - move from TCPDF to PrinceXML ( www.princexml.com/ ). Of all the PDF generators I've reviewed, this one turned out to be the most correct. It also merges several HTML into one PDF. And the memory eats very modestly in comparison with the rest.
Previously, it was spinning on Windows - there were no problems.
Perhaps the problem is in the implementation of pdftk.exe, which, trying to simultaneously read from 2 identical files, is locked somewhere

N
Nikolai Turnaviotov, 2013-06-21
@foxmuldercp

Firstly, I would try to debug the process by inserting debugging information wherever possible with reference to the client session (client a, client b, client c) and the command execution time and the time that this command was executed, maybe this will help figure it out.
Secondly, switching from cmd to powershell is not difficult, and writing scripts on it is a pleasure of the object .Net language with extensive debugging capabilities.
I won’t tell you about PHP, yes, I’m not strong in it, but something tells me that the problem is not in it.
If you already need a site under Win, in principle, if you have a technical specification, you can implement it using C # + Asp.Net and MVC, natively and without hemorrhoids, I can also try to help with this, in general.

R
rPman, 2013-06-22
@rPman

It looks as if the processes somewhere are accessing a shared resource and waiting for it to be released (some kind of crooked method for implementing a queue), it was already advised above to carefully debug and identify exactly where the plug is formed in the code, by the usual verbose logging.
Transfer all the generation code to a separate process launched outside the IIS session (by a separate service or even a standalone application) on the same php through some simple queue, and leave the task to the web server - put the task in the queue, wait for it to complete, give the result.
The advantage of this separation is more complete control over the load (the process processing tasks in the queue can be multi-threaded) and most importantly, it will run in the context of a normal application without any internal features and glitches that IIS generates (after all, you yourself showed that only under IIS there is a problem).
And most importantly, you won’t have to rewrite anything, in fact, just add a task queue and its processing.

D
Denisio, 2013-06-23
@Denisio

Generate PDF in a separate service. Running external software from within IIS is a very bad idea.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question