문제

I'm currently using the Pygments for PHP plugin that is located here: http://derek.simkowiak.net/pygments-for-php/.

The line that actually calls Pygments from that code is an exec() passed:

pygmentize -f html $extra_opts -l $language $temp_name
as the command. This all works fine, and I get back the output and it is formatted by the plugin.

What I would like to happen at the same time is for Pygments to create an image of it, so I pass exec() a similar command:

pygmentize -f png $extra_opts -l $language -o $full_image_path/$output_file.png $temp_name
This is where I run into a problem. The image never shows up in the expected folder.

However, if I var_dump() that command string before I exec() it and take it and run it straight from the command line, it works fine.

I have tried echoing exec('whoami') which tells me that the PHP user is www-data. I've tried giving permissions to www-data and changing ownership to www-data on the folder where I store the images. I've also tried changing permissions to 777 just to see what would happen, and the answer is nothing.

Is there something I'm missing? I'm running out of ideas to try. Thank you!

Edit: Another thing that I've checked is the output from the exec command, and the return value. It outputs an empty array, and it returns 1 as the return value.

Edit 2: After seeing that that directory should be writeable/readable for the PHP user, is it possible that pygments doesn't have permission to write it as a specific user? I'm not sure this makes sense, as when I run it myself it works fine, and in fact, when PHP runs it with the HTML lexer, it is able to run. I'm not very experienced in Python, so I don't know if this is a potential issue.

도움이 되었습니까?

해결책 2

Ended up being an issue with the font that was installed for use by the www-root user. Apparently the one that is used by default for Pygments was installed only for the user that I was running as when I use the command line.

The way I was able to figure this out, was running exec("$command 2>&1", $out, $code);.

The extra 2>&1 redirects stderr into the output for me to see the issue.

The $out parameter showed the FontNotFound error that pygments was throwing.

I changed the font that Pygments used via the command line using: full,style=manni,cssclass=pygmentize_kbOKBd,font_name='DejaVu Sans Mono' -l php -o /srv/www/path/to/images/uploads/2513732976ad4b7.02729290.png /tmp/pygmentize_kbOKBd after finding which fonts I had available to me.

To see which fonts I had available to me as the user running the script, I just ran fc-list in an exec() command for Ubuntu, and checked the output of that for the list of available fonts.

다른 팁

I guess you cannot do it like this.

$output_file.png

Try

$file = $output_file.".png"

and substitute in the exec

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top