Executing external program(kindlegen) from PHP doesn't finish without any error

122 views Asked by At

I'm creating mobi files generator using PHP and kindlegen program.

I have: - kindlegen file in in the path /var/www/webook_disk/ - PHP script

echo exec(./kindlegen /var/www/webook_disk/books_drafts/1234/book.opf -o 1234.mobi)
  • book files in /var/www/webook_disk/books_drafts/1234/

When I run the PHP script I get this log:

Info(prcgen):I1002: Parsing files  0000002

When I run ./kindlegen /var/www/webook_disk/books_drafts/1234/book.opf -o 1234.mobi from console I get this log:

*************************************************************
 Amazon kindlegen(Linux) V2.9 build 1028-0897292 
 A command line e-book compiler 
 Copyright Amazon.com and its Affiliates 2014 
*************************************************************

Info(prcgen):I1047: Added metadata dc:Title        "Przykładowa książka"
Info(prcgen):I1047: Added metadata dc:Creator      "webook"
Info(prcgen):I1047: Added metadata dc:Publisher    "webook"
Info(prcgen):I1002: Parsing files  0000002
Info(prcgen):I1016: Building enhanced PRC file
Info(prcgen):I1015: Building PRC file
Info(prcgen):I1006: Resolving hyperlinks
Warning(prcgen):W14001: Hyperlink not resolved:  /2010/07/Wyprawa-zlodzieja-do-Mazeri.html
Warning(prcgen):W14002: Some hyperlinks could not be resolved.
Info(prcgen):I1008: Resolving start reading location
Warning(prcgen):W14016: Cover not specified
Info(pagemap):I8000: No Page map found in the book
Info(prcgen):I1045: Computing UNICODE ranges used in the book
Info(prcgen):I1046: Found UNICODE range: Basic Latin [20..7E]
Info(prcgen):I1046: Found UNICODE range: Latin Extended-A [100..17F]
Info(prcgen):I1046: Found UNICODE range: Latin-1 Supplement [A0..FF]
Info(prcgen):I1046: Found UNICODE range: General Punctuation - Windows 1252 [2013..2014]
Info(prcgen):I1017: Building PRC file, record count:   0000025
Info(prcgen):I1039: Final stats - text compressed to (in % of original size):  61.30%
Info(prcgen):I1040: The document identifier is: "PrzykKadowa_ksiBQka"
Info(prcgen):I1041: The file format version is V5
Info(prcgen):I1031: Saving PRC file
Info(prcgen):I1033: PRC built with WARNINGS!
Info(prcgen):I1007: Resolving mediaidlinks
Info(prcgen):I1011: Writing mediaidlinks
Info(prcgen):I1009: Resolving guide items
Info(prcgen):I1017: Building PRC file, record count:   0000027
Info(prcgen):I1039: Final stats - text compressed to (in % of original size):  60.45%
Info(prcgen):I1041: The file format version is V8
Info(prcgen):I1032: PRC built successfully
Info(prcgen):I15000:  Approximate Standard Mobi Deliverable file size :   0002209KB
Info(prcgen):I15001:  Approximate KF8 Deliverable file size :   0002215KB
Info(prcgen):I1037: Mobi file built with WARNINGS!

It looks like PHP script doesn't finish executing kindlegen program and stops on Info(prcgen):I1002: Parsing files 0000002

What could be the reason?

**UPDATE 1 ** When I changed php command from exec to shell_exec the output is like that: I changed the command to shell_exec and here are logs:

*************************************************************
 Amazon kindlegen(Linux) V2.9 build 1028-0897292 
 A command line e-book compiler 
 Copyright Amazon.com and its Affiliates 2014 
*************************************************************

Info(prcgen):I1047: Added metadata dc:Title        "Przykładowa książka"
Info(prcgen):I1047: Added metadata dc:Creator      "webook"
Info(prcgen):I1047: Added metadata dc:Publisher    "webook"
Info(prcgen):I1002: Parsing files  0000002

So it doesn't matter which command I use. The problem is that it stops suddenly.

Today I discovered that there was a error reported in var/crash: But the log is very long, so I put it in the gist: https://gist.github.com/blaszczakphoto/a32fd65384fcd8dd4f48751bfd78e699

1

There are 1 answers

1
AudioBubble On

Looking at the documentation, the return value of exec is the following:

The last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.

You may want to use shell_exec or passthru.