Question

Is it possible to use Python (specifically Pygments) with PHP? Currently, I have a phpBB forum that I'm developing for and JS Syntax Highlighters just haven't been working for me. There's already a GeSHI mod, but I want to develop something myself just for experience.

Also, would there be performance issues?

Was it helpful?

Solution

Pretty much the only way to perform that integration (with PHP as the dominant language) is to shell out. This means starting python manually every time you need it.

That can be a little slow if you need to do it a lot. You can mitigate this by creating the syntax hilite when posts are created or edited, not when viewing.

OTHER TIPS

There is now a library for this at:

http://derek.simkowiak.net/pygments-for-php/

If you're interested in diving into Python, you could write an external script or server application to update new posts with syntax-highlighted code. If it were me, I'd retain the original code in one database column and place the syntax-highlighted version in another.

A simple script to update new posts in batches could run as a cron job at whatever interval you find ideal.

To support a near real-time scenario, you could write a server application that sits and waits to be notified of new posts one at a time. For example, upon processing a new post, the PHP application could send the highlighting application a message through an AMQP queue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top