Forum Moderators: coopster

Message Too Old, No Replies

Access a program outside of PHP

How to access gs (ghostscript) through PHP.

         

The_Warden

10:08 pm on Sep 9, 2003 (gmt 0)

10+ Year Member



Hi. I'm trying to develop a web interface to the ghostscript (gs) application. I have the ghostscript syntax down perfectly in the console. Now when I go to try and do it in PHP I get nothing. No errors, nothing just a blank page with PHP logs turned on and errors turned on.

I'm running Apache with PHP 4.3.3 on OpenBSD 3.3 i386. In my case Apache (httpd) is chrooted to /var/htdocs/. So I figured I would have to copy ghostscript and all it's dependencies to /var/htdocs/ at least for it to work. Still nothing. Here's the code I used below. At this point I do not know what direction to go to get this to work or if it is even possible. I've tried exec(), system() and popen() api functions. I get nothing no results, no errors what so ever. BTW, ghostscript does appear to work fine in the chrooted directory via the console. At this point the below code is all I have. The sytax for ghostscript shown below just outputs the data of the 2 PDF files to the pdfwrite so it will merge them together into a merged.pdf file. Quite simple actually.

$szPipe = popen("/htdocs/gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=/htdocs/merged.pdf /htdocs/Sep08-113518.pdf
/htdocs/Sep08-113523.pdf", "r");

Any ideas or direction on how to do this would be greatly appreciated.

Thanks!

san_garrafa

11:33 pm on Sep 9, 2003 (gmt 0)

10+ Year Member



[edit]
should read the message carefuly before posting. Sorry about that.

Is gs executable by the user apache is running as?

vincevincevince

11:46 pm on Sep 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



look into passthru()

The_Warden

2:08 pm on Sep 10, 2003 (gmt 0)

10+ Year Member



san_garrafa

Yes gs is executable by the user that apache (httpd) runs as, www. I moved gs and all dependencies under /var/www/htdocs/ so it could be accessible.

vincevincevince

I tried using passthru() and it does not appear to do anything. When I echo it out it shows "127".

passthru("/htdocs/gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=/htdocs/merged.pdf /htdocs/Sep08-113518.pdf /htdocs/Sep08-113523.pdf", $szPipe);

[edited by: jatar_k at 3:15 pm (utc) on Sep. 10, 2003]
[edit reason] fixed sidescroll [/edit]

vincevincevince

2:11 pm on Sep 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



after the passthru has it created the file /htdocs/merged.pdf?

if it IS created, then try header("location: http:*//yourdomain.com/merged.pdf"); following the passthru

The_Warden

2:54 pm on Sep 10, 2003 (gmt 0)

10+ Year Member



vincevincevince

No sorry I should have made myself more clear. The file was not created the passthru() appears to have done nothing at all. No errors nothing.

The_Warden

3:08 pm on Sep 10, 2003 (gmt 0)

10+ Year Member



Hi all. I thought I should result to something simple to get this to work. I took the example from the PHP manual system() page. In this example is it suppose to return "Last Line of Output: " and "Return value: 127"? This occurs with system() and passthru(). I thought it should return the last line of a ls would show in the console.


<?php
echo '<pre>';

// Outputs all the result of shellcommand "ls", and returns
// the last output line into $last_line. Stores the return value
// of the shell command in $retval.
$last_line = system('ls', $retval);

// Printing additional info
echo '
</pre>
<hr>Last line of the output: '.$last_line.'
<hr>Return value: '.$retval;
?>