01-15-2014, 07:35 PM | #1 |
Groupie
Posts: 171
Karma: 86271
Join Date: Feb 2012
Device: iPad, Kindle Touch, Sony PRS-T1
|
kindlegen via php on linux server
hi all,
i'm trying to set up a server-side EPUB>MOBI converter on a linux server using kindlegen via php. i've uploaded the linux kindlegen, but am unable to invoke it. i'm using the following: Code:
<?php session_start(); ob_end_flush(); ob_start(); set_time_limit( 0 ); error_reporting( 0 ); $ebook = "book.epub"; $cwd = getcwd() . "/"; $cmd = $cwd . "kindlegen_linux_2.6_i386_v2_9/kindlegen " . $ebook; $descriptorspec = array( 0 => array( "pipe", "r" ), // stdin is a pipe that the child will read from 1 => array( "pipe", "w" ), // stdout is a pipe that the child will write to 2 => array( "pipe", "w" ) // stderr is a pipe that the child will write to ); ob_flush(); $process = proc_open( $cmd, $descriptorspec, $pipes ); echo "<p>"; if ( is_resource( $process ) ) { while ( $s = fgets( $pipes[1] ) ) { echo str_repeat( ' ',1024*64 ); // whitespace print $s . "<br />"; if ( $e = fgets( $pipes[2] ) ) { echo str_repeat( ' ',1024*64 ); print $e . "<br />"; ob_flush(); } ob_flush(); } } else{ echo "error"; } echo "</p>"; proc_close( $process ); Code:
<?php $ebook = "book.epub"; $cwd = getcwd() . "/"; $cmd = $cwd . "kindlegen_linux_2.6_i386_v2_9/kindlegen " . $ebook; exec( $cmd ); googling isn't turning much up, so if anyone had any suggestions i'd be greatful! Last edited by mzmm; 01-15-2014 at 08:18 PM. |
01-16-2014, 04:29 AM | #2 |
Evangelist
Posts: 404
Karma: 2200000
Join Date: May 2012
Device: kt
|
Maybe wrong permissions? Try to chown kindlegen binary to web server user and chmod 777 and see if it helps.
Or maybe safe mode is enabled? Then look at safe_mode_exec_dir parameter. Print the output and return status of the exec command and see the error message. Last edited by baf; 01-16-2014 at 04:34 AM. |
Advert | |
|
01-16-2014, 10:54 AM | #3 |
Groupie
Posts: 171
Karma: 86271
Join Date: Feb 2012
Device: iPad, Kindle Touch, Sony PRS-T1
|
@baf, thanks for the reply. i changed the kindlegen permissions to 777 but don't think i want to start messing with chown. i'm on PHP 5.4 so can't safe_mode_exec_dir().
errors weren't being reported on the remote server, but moved to local and now get Code:
Error(prcgen):E21008: can not write to output file. If the file is being used by any other application, please close it. getting closer Last edited by mzmm; 01-16-2014 at 10:59 AM. |
01-16-2014, 01:14 PM | #4 |
Evangelist
Posts: 404
Karma: 2200000
Join Date: May 2012
Device: kt
|
Try to chmod 777 the directory in which mobi file will be created.
And don't be afraid of chown |
01-16-2014, 01:33 PM | #5 |
BLAM!
Posts: 13,478
Karma: 26012494
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
|
In fact, I'd say that if you want to be afraid of permissions, you should be more afraid of chmod than of chown .
|
Advert | |
|
01-16-2014, 02:23 PM | #6 |
Going Viral
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
Plus - get your ob_start and ob_flush into matched pairs.
|
01-20-2014, 10:03 AM | #7 | |
Groupie
Posts: 171
Karma: 86271
Join Date: Feb 2012
Device: iPad, Kindle Touch, Sony PRS-T1
|
Quote:
@NiLuJe, thanks, still new to php, so chmod'ing from the command line seems more controlled to me right now. got to hit the php documentation a bit more. @knc1, ok, thanks for that. got to spend some more time with the docs |
|
01-20-2014, 10:26 AM | #8 |
Grand Sorcerer
Posts: 27,553
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Not to be downer, but you might want to keep kindlegen's licensing terms in mind here. I have no idea if the online converting service you intend to provide (IF you intend to provide) runs afoul of those terms or not, but I do know that the terms of the license do not allow kindlegen-created ebooks to be sold anywhere but Amazon. Might want to at least warn potential users of that.
|
01-20-2014, 01:08 PM | #9 |
Groupie
Posts: 171
Karma: 86271
Join Date: Feb 2012
Device: iPad, Kindle Touch, Sony PRS-T1
|
@DiapDealer—not a downer at all, thanks very much for the input.
fwiw, the ebooks would be made available for free, and the public would have no access to the conversion tools. good point, though, and probably a good idea to get some advice on this aspect |
01-20-2014, 01:46 PM | #10 | |
Evangelist
Posts: 404
Karma: 2200000
Join Date: May 2012
Device: kt
|
Quote:
Remember that 777 permissions are good for testing. In real environment you should be careful about granting permissions to everybody, especially rights to write to some folder or execute a file. Limiting it to the web server (or fastcgi) owner and particular location should be enough. Also look carefully at stuff that users upload to your server. Don't let them execute anything nasty |
|
01-20-2014, 02:53 PM | #11 |
BLAM!
Posts: 13,478
Karma: 26012494
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
|
Yup, feeding 'random' unvalidated data to a closed source binary sounds fun... ^^.
|
01-22-2014, 09:10 AM | #12 |
Guru
Posts: 608
Karma: 1588610
Join Date: Jan 2012
Device: Kindle Scribe
|
|
Tags |
kindlegen, mobi, php, server |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
COPS : Calibre OPDS PHP Server | vlad59 | Related Tools | 1911 | 03-04-2024 06:39 AM |
PHP+Apache web server for calibre ... | chaley | Related Tools | 254 | 04-28-2014 08:18 PM |
Does anyone have older tarballs of KindleGen for Linux? | clee | Kindle Formats | 0 | 09-20-2013 03:45 PM |
SPCS: Simple PHP Content Server for Calibre | Fmstrat | Related Tools | 6 | 05-29-2013 07:26 PM |
kindlegen running on Linux | JiYu | Amazon Kindle | 0 | 09-20-2010 06:08 AM |