# Apache/PHP/pdftk system command execution issue

## dageyra

I am really banging my head against the wall here.  I have a PHP script that can be run from either CLI or webserver, it just interfaces with phptk to concat some PDFs.  If I run the script in CLI, it works.  If I run the string that I pass to the exec function in the shell, it works.  If I take the same PHP script and let it run from the webserver, the command starts up (I can see it in the process list), and never ends.

I have tried making all of this work out of /tmp, with full permissions, I have created a special directory with full permissions for the apache web user, but nothing seems to work.  Normal commands like "ls" work fine from the webserver, but when I put pdftk in, I get the following info from ps:

```

22675 ?        S      0:00 sh -c cd '/sites/pdfwriter' ; pdftk /sites/pdfwriter/17399.pdf stamp /sites/pdfwriter...

22676 ?        Sl     0:00 pdftk /sites/pdfwriter/17399.pdf stamp /sites/pdfwriter/A.pdf output /sites/pdfwriter....

```

This page will run continuously, even though it takes a matter of seconds if the command is run in shell or the PHP file is ran under the CLI.

What could possibly be going wrong here?  Thanks in advance for your help.

----------

## dageyra

Bump?  I've tried looking into a library path issue, no luck, I am seeing if pdftk can handle simpler operations, like a simple concat.

----------

## dageyra

I have determined the problem is related to the size of the input PDFs.  pdftk runs and completes successfully if I use small PDF input files no matter the operation (concat, watermark, etc).  However, with the needed files (which are over 8 MB in size), the operations never complete regardless of which operation I try.

Again, if I run the same PHP script from the command line under my username, pdftk works fine regardless of the input file size.  I then try to run the same PHP file from the apache webserver and the problem arises.

Does anyone have an idea as to what could be causing the disconnect here?

----------

## dageyra

The limitation appears to be in the creation of the output file.  I was able to get the script to run on a command that creates a file < 8 MB, anything 8+MB never ends.  I think I'm getting much closer.

----------

## randalla

 *dageyra wrote:*   

> The limitation appears to be in the creation of the output file.  I was able to get the script to run on a command that creates a file < 8 MB, anything 8+MB never ends.  I think I'm getting much closer.

 

I believe that you are running into a threading issue. I ran into this yesterday when calling pdftk via PHP's exec() command running under apache 2.2.15. Every time it would lock up, and force me to kill it manually. Running strace shows that it would get stuck here:

futex(0xb76fbcc8, FUTEX_WAIT_PRIVATE, 0, NULL

This happened on all of the machines I tested on that were running 32-bit (three tested). On our 64-bit machines, though, it did not happen. All machines are running exactly the same versions of everything (kernel 2.6.32-gentoo-r7, apache 2.2.15, php 5.2.13-pre10-gentoo).

On the 32-bit machines, I was able to work around it by disabling threads in both apache and php via the use of the /etc/portage/package.use file:

www-servers/apache -threads

dev-lang/php -threads ldap postgres mysql

Not sure if this is much help so far after your initial post, but maybe it will help someone else down the line.

Adam.

----------

## dageyra

 *randalla wrote:*   

>  *dageyra wrote:*   The limitation appears to be in the creation of the output file.  I was able to get the script to run on a command that creates a file < 8 MB, anything 8+MB never ends.  I think I'm getting much closer. 
> 
> I believe that you are running into a threading issue. I ran into this yesterday when calling pdftk via PHP's exec() command running under apache 2.2.15. Every time it would lock up, and force me to kill it manually. Running strace shows that it would get stuck here:
> 
> futex(0xb76fbcc8, FUTEX_WAIT_PRIVATE, 0, NULL
> ...

 

Thanks for following up on this for me Adam, and actually the problem does still exist.  I just broke the PDFs into smaller multiple PDFs, which does not really help in situations where this is not possible.  I'm interested in what you did for 64-bit machines because this is a newer server configured according to the AMD64 handbook.  I do not know anything about the strace command, but did you determine that it was the 8 MB barrier causing the problem?  I can always build PDFs where the resulting PDF is less than 8 MB, even 7.99 MB, but anything 8 MB and over, it never finishes.  For working builds, it is very fast, so it's not like it's running out of resources or anything.

Perhaps I have some configuration incorrect that is making it build as if x86 instead of AMD64?

Thanks again for following up, I would like to have some formalized resolution to this.

----------

