简体   繁体   中英

PHP exec using LP command fails on Mac OS X

I am trying to spool a file to a printer attached to the server using PHP.

I send a command such as lp -d 'Brother_QL-570' '/Users/user_name/Documents/wwwroot/mmsprint/mmsUw8Vv9 using EXEC in PHP and get a return value of 5 . The command works fine in the terminal window.

If I send ls , whoami etc, the command executes fine.

whoami and ls live in /bin, so I created a symbolic link for lp and that made no difference.

Also tried /usr/bin/lp and that did not work either. I'm pulling what little hair I have left out over this.

Safe mode is off. The path variables are the same between PHP and my terminal environment. I am running MAMP on Lion.

FWIW, the command cat /Users/user_name/Documents/wwwroot/mmsprint/mmswKJqYK | lp -d Brother_QL-570 cat /Users/user_name/Documents/wwwroot/mmsprint/mmswKJqYK | lp -d Brother_QL-570 has a return value of 133 .

This is my code:

$temp_file = tempnam("./", 'mms');
$pdf->Output($temp_file, "F");
$pdf->Close();
$cmd = "lp -d 'Brother_QL-570'  '".$temp_file."'";
exec($cmd,$output,$retval);
error_log("-----cmd=".$cmd."\n", 3, "printCard.log");
foreach ($output as $a) {
    error_log("-----output=".$a."\n", 3, "printCard.log");
}
error_log("-----retval=".$retval."\n", 3, "printCard.log");

Any thoughts? What am I missing? This should be easy. Argh!!

It turns out to be a problem with MAMP. I googled "MAMP exec fails" and came up with several good answers. Its a compatibility problem with libraries. I added DYLD_LIBRARY_PATH='' && to the command and Bob's my uncle. Thanks for the replies.

I found a similar solution to the one mentioned about using DYLD_LIBRARY_PATH='' && . Using this worked for me, so I tried to find a more permanent fix than including this in all my code. I opened up the file /Applications/MAMP/Library/bin/envvars and commented the following two lines out:

DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH

After restarting apache, this is working GREAT! Not sure why this is happening to me though. Might have to do something with the fact that I am running 2 virtual hosts.

What is the output from the command?

Most likely the PHP user (apache probably) has no permission to print things. Add that user to the lp group. (Assuming macs work similar to unix in this.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM