Archive for category php

The problem with choice

Tried to find a HTML to PDF generator for PHP the last few days … not easy.
I first found much about TCPDF. From the results it looked quite promising.
As it turns out it was not so easy to just put in your HTML like on the webpage, and get a good looking PDF.
After some testing i searched for alternatives and found DOMPDF. The render results for my page were much better than before with tcpdf. But as i tried a newer version it broke my layout completely (To be exact, somewhere between r305 and r309 of dompdf).
That lead me to submit a bug report. On the reported bugs i found someone pointing to another html2pdf php library: MPDF
mpdf does render my HTML good, too. It also prints some textboxes in the documents that dompdf did not. It has some other oddies, but seems quite nice till now.

The conclusion:
I yet not know which engine to choose. Till now dompdf and mpdf did the best job for me. dompdf produces a pdf with size of 6kb whereas mpdf uses 69kb. YMMV with different HTML, so you are on your own.
There are so many HTML to PDF engines out there, that it is not easy to choose. Thats only 3 i tested, and there are some more out there like fpdf, pdflib …
One of them is better on some tags, the other is better with some other. I keep wondering why not some of the engines could unite. More developers could mean better results. Lets assume there are 10 engines out inventing 10 wheels at the same time … what a waste of time.

Advertisements

Leave a comment

APC cache twice as fast as memcached if run on only one server

Ok, as i told yesterday i would try the cache wrapper today.
In my case APC with the wrapper is twice as fast as memcached, as i am running only one server. The wrapper gives very little overhead, but its worth it, because you can change the cache easily. Of course if you run more than one server memcached could be the one you want as it can distribute the cache over all machines.

Leave a comment

PHP wrapper class for cache engines | Neo22s

PHP wrapper class for cache engines | Neo22s.

Good to know this class called wrappercache. Within the next days  i will try this wrapper and will check the performance of my scripts that now use memcached.

1 Comment

Memcached vs. mysql query cache

And the winner is (in this case): memcached
On my site there is a course scheduler, and today i switched one simple query to fill memcached every 5 minutes.

Before this special site took around 0.09 seconds to load,
With memcached it takes 0.047 seconds. Thats almost half the time.
When filling memcached its 0.13 seconds, so is a bit slower, but most time this little change improves the site.
The query that now gets it boost from memcached is just a query that gets date and time for a specific course, so it would run around 100 times on that page.

As i use the query cache from mysql for both queries i can say, that even if memcached is running on the same machine, memcached won for this case.
In other cases the query cache may win.

, ,

Leave a comment

Found easy example for memcached with php and mysql

Just wanted to share that, and will try it next week when back at work:
Memcached example

Hope it gets me little performance boost, or at least less load on the server.

Leave a comment

Openstreetmap tiles over https with openlayers and server redirect

Good news: Redirect from https to http works for tiles with openlayers. This prevents mixed mode warning in Internet Explorer

I recently got some problems on a https site. I included a map from openstreetmap.org and the Internet Explorer started complaining about mixed content. Btw. it is very annoying, that for IE7 you have to click YES on the dialog, and for IE8 you have to click NO.

The openlayers javascript files come from my https server so they are no problem. The only remaining reason for this were that the tiles coming from the openstreetmap server over http. After some tries with proxying the tiles over a php script, which was too slow, finally the solution was so easy.
Writing a little tiles.php which just redirects to openstreetmap instead of proxying, and complaints from IE stopped, as the tiles.php is on the https site:

$x = intval($_GET['x']);
$y = intval($_GET['y']);
$z = intval($_GET['z']);
$r = strip_tags($_GET['r']);
if(empty($r)) $r="mapnik";
$server = array();
switch ($r) {
    case 'mapnik':
        $server[] = 'a.tile.openstreetmap.org';
        $server[] = 'b.tile.openstreetmap.org';
        $server[] = 'c.tile.openstreetmap.org';

        $url = 'http://' . $server[array_rand($server)];
        $url .= "/" . $z . "/" . $x . "/" . $y . ".png";
        break;

    case 'osma':
    default:
        $server[] = 'a.tah.openstreetmap.org';
        $server[] = 'b.tah.openstreetmap.org';
        $server[] = 'c.tah.openstreetmap.org';

        $url = 'http://' . $server[array_rand($server)] . '/Tiles/tile.php';
        $url .= "/" . $z . "/" . $x . "/" . $y . ".png";
        break;
}

header("HTTP/1.1 301 Moved Permanently");
header("Location: $url");
exit();

The openlayers layer now just has to point to this little redirection and everything is fine:

layerMapnik = new OpenLayers.Layer.OSM("Mapnik","tiles.php?z=${z}&x=${x}&y=${y}&r=mapnik");

Inspired by http://wiki.openstreetmap.org/wiki/ProxySimplePHP

, ,

25 Comments

PHP, SQL and sorting order

I searched for a good way to implement changing of sort order in php easily, but did not find a good way, so today i developed some handy code for sort order handling in PHP and want to share it. Maybe you find some downsides or maybe you like it.
You only have to configure the orderarray with your default sort order. The orderby parameter is filtered against that array, so there should be no danger of sql injection.

$orderarray=array(
  "Modul" => "name ASC",
  "Date"=>"date ASC",
  "Text" =>"description ASC");
if(!isset($_GET['orderby'])){
  $customorder=$orderarray;
}else{
  $customorder=array_intersect(explode(",",$_GET['orderby']),$orderarray);
}
$orderby=implode(", ", $customorder);
foreach($customorder as $key=>$value){
  $orderstring=implode(",", array_unique(array_merge(array($key=>$value), $customorder)));
  $orderlinks.='<a href="index.php?orderby='.$orderstring.'">'
             . array_search($value,$orderarray) .'</a>';
}
print $orderlinks;
$query="SELECT name, date, desciption FROM some_table ORDER BY $orderby";

Leave a comment

%d bloggers like this: