Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 01-15-2014, 07:35 PM   #1
mzmm
Groupie
mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.
 
mzmm's Avatar
 
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 );
because i'd like to be able to report back to the user realtime, but even

Code:
<?php

$ebook  = "book.epub";
$cwd    = getcwd() . "/";
$cmd    = $cwd . "kindlegen_linux_2.6_i386_v2_9/kindlegen " . $ebook;

exec( $cmd );
is reloading a white screen without generating the mobi file. the paths are correct, so i'm not sure what the issue would be, or even how to troubleshoot it.

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.
mzmm is offline   Reply With Quote
Old 01-16-2014, 04:29 AM   #2
baf
Evangelist
baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.
 
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.
baf is offline   Reply With Quote
Advert
Old 01-16-2014, 10:54 AM   #3
mzmm
Groupie
mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.
 
mzmm's Avatar
 
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.
i'm guessing that kindlegen doesn't have sufficient permissions to write the mobi file, or that it's trying to write the mobi first to "/tmp/mobi-3VEzNm" rather than to the cwd

getting closer

Last edited by mzmm; 01-16-2014 at 10:59 AM.
mzmm is offline   Reply With Quote
Old 01-16-2014, 01:14 PM   #4
baf
Evangelist
baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.
 
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
baf is offline   Reply With Quote
Old 01-16-2014, 01:33 PM   #5
NiLuJe
BLAM!
NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.
 
NiLuJe's Avatar
 
Posts: 13,477
Karma: 26012492
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 .
NiLuJe is offline   Reply With Quote
Advert
Old 01-16-2014, 02:23 PM   #6
knc1
Going Viral
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
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.
knc1 is offline   Reply With Quote
Old 01-20-2014, 10:03 AM   #7
mzmm
Groupie
mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.
 
mzmm's Avatar
 
Posts: 171
Karma: 86271
Join Date: Feb 2012
Device: iPad, Kindle Touch, Sony PRS-T1
Quote:
Originally Posted by baf View Post
Try to chmod 777 the directory in which mobi file will be created.
And don't be afraid of chown
@baf, thanks, turns out this was the issue. i'll have to read up more on chown to get more comfortable with it, everything i'd come across in cursory google searches was about how people mangled their sites by messing with the permissions.

@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
mzmm is offline   Reply With Quote
Old 01-20-2014, 10:26 AM   #8
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 27,465
Karma: 192992430
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.
DiapDealer is online now   Reply With Quote
Old 01-20-2014, 01:08 PM   #9
mzmm
Groupie
mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.
 
mzmm's Avatar
 
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
mzmm is offline   Reply With Quote
Old 01-20-2014, 01:46 PM   #10
baf
Evangelist
baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.baf ought to be getting tired of karma fortunes by now.
 
Posts: 404
Karma: 2200000
Join Date: May 2012
Device: kt
Quote:
Originally Posted by mzmm View Post
@baf, thanks, turns out this was the issue. i'll have to read up more on chown to get more comfortable with it, everything i'd come across in cursory google searches was about how people mangled their sites by messing with the permissions.
Great that you managed to solve it.
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
baf is offline   Reply With Quote
Old 01-20-2014, 02:53 PM   #11
NiLuJe
BLAM!
NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.
 
NiLuJe's Avatar
 
Posts: 13,477
Karma: 26012492
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... ^^.
NiLuJe is offline   Reply With Quote
Old 01-22-2014, 09:10 AM   #12
aditya3098
Guru
aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.
 
Posts: 608
Karma: 1588610
Join Date: Jan 2012
Device: Kindle Scribe
Quote:
Originally Posted by NiLuJe View Post
Yup, feeding 'random' unvalidated data to a closed source binary sounds fun... ^^.
Do that as root, and sell locked down devices with that installed, and you might as well say amazon made it
aditya3098 is offline   Reply With Quote
Reply

Tags
kindlegen, mobi, php, server

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

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


All times are GMT -4. The time now is 07:58 AM.


MobileRead.com is a privately owned, operated and funded community.