wolfan Posted April 14, 2010 Share Posted April 14, 2010 Hi There, I have a problem with this piece of code and I'm hoping someone can help me. The code actually does execute as I expect, the problem is with the line which executes a shell script. What it does is generate a PDF file on the server after calling that command which is a python script to generate PDFs. I then download the PDF from the server. The problem is that the command takes more a few seconds to work, so it gets to the end before the PDF actually has time to generate and when I check the server the text file ($filename) is created but not the PDF. When I run the exact same command that is run in "$result = `rml2pdf $filename`;" it works just fine but just after a second. As you can see I thought trowing a pause in there would help that, but it didn't. die($result) returns nothing. Can anyone help? ***SNIP*** $fieldList = array('Telephone'=>array('Telephone','text'), 'Fax'=>array('Fax','text'), 'FName'=>array('Full Name','text'), 'Title'=>array('Title','text'), 'Email'=>array('Email','text')); $pdfFileName = 'buscard'.$id.'.pdf'; $filename = 'temprml'.$id.'.rml'; if(isset($_POST['btnSubmit'])) { foreach($fieldList as $k=>$v);{ $rml = str_replace("!".$k."!",$_POST[$k],$rml); } $oFile = fopen($filename,'w') or die("Can't open file"); fwrite($oFile, $rml); fclose($oFile); $result = `rml2pdf $filename`; echo $result; sleep(15); $result = trim($result); header('Content-Type: application/octet-stream'); header("Content-Disposition: attachment; filename=$pdfFileName"); header('Content-Transfer-Encoding: binary'); readfile($pdfFileName); } ***SNIP*** Quote Link to comment https://forums.phpfreaks.com/topic/198558-shell-exec-problems/ Share on other sites More sharing options...
roopurt18 Posted April 14, 2010 Share Posted April 14, 2010 Executing a command like that doesn't fork it into the background so your PHP script is not finishing before the PDF has a chance to generate. In fact PHP will wait for the command to finish before resuming execution. My guess is rml2pdf is not in your system's PATH variable so when you execute the command it fails with command not found. Or it is possible that $filename is a relative path and the PDF is generated but it's not where you expected it to be. Quote Link to comment https://forums.phpfreaks.com/topic/198558-shell-exec-problems/#findComment-1041946 Share on other sites More sharing options...
wolfan Posted April 14, 2010 Author Share Posted April 14, 2010 Thank you for the suggestions, but I tried running rml2pdf on a number of different places on my server and it ran just fine. Also, I searched the server for the file which was generated and it's no where to be found. Quote Link to comment https://forums.phpfreaks.com/topic/198558-shell-exec-problems/#findComment-1041986 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.