Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.3.0

Request #8380 Use readfile instead of fread and echo
Submitted: 2006-08-07 22:25 UTC
From: php at adaniels dot nl Assigned: jausions
Status: Closed Package: Image_GraphViz (version 1.2.1)
PHP Version: 5.1.4 OS:
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 34 - 33 = ?

 
 [2006-08-07 22:25 UTC] php at adaniels dot nl (Arnold)
Description: ------------ First of all, love graphviz and your package. I have a small suggestion though. Currently you are using fread and than echo. When the generated image is large, this will affect memory usage. It might be better to use fread instead. Adding a step where the image is saved to file, also gives an option to save without reading it back to php and than writing again. Saying this, I had not yet rendered any image where the size was a real problem. Test script: --------------- // output image $gv->image(); // fetch image $data = $gv->fetch(); // save image to file $outputfile = $gv->saveImage(); rename($outputfile, dirname(__FILE__) . '/img/'); Expected result: ---------------- Currently: function image($format = 'svg') { if ($data = $this->fetch($format)) { ... echo $data; } } function fetch($format = 'svg') { if ($file = $this->saveParsedGraph()) { $outputfile = $file . '.' . $format; $command = $this->graph['directed'] ? $this->dotCommand : $this->neatoCommand; $command .= ' -T' . escapeshellarg($format) . ' -o' . escapeshellarg($outputfile) . ' ' . escapeshellarg($file); @`$command`; @unlink($file); $fp = fopen($outputfile, 'rb'); if ($fp) { $data = fread($fp, filesize($outputfile)); fclose($fp); @unlink($outputfile); } return $data; } return FALSE; } Actual result: -------------- Better might be: function image($format = 'svg') { if ($outputfile = $this->saveImage($format) && filesize($outputfile)) { ... fileread($outputfile); @unlink($outputfile); } } function fetch($format = 'svg') { if ($outputfile = $this->saveImage($format)) { $fp = fopen($outputfile, 'rb'); if ($fp) { $data = fread($fp, filesize($outputfile)); fclose($fp); @unlink($outputfile); } return $data; } return FALSE; } function saveImage($format = 'svg') { if ($file = $this->saveParsedGraph()) { $outputfile = $file . '.' . $format; $command = $this->graph['directed'] ? $this->dotCommand : $this->neatoCommand; $command .= ' -T' . escapeshellarg($format) . ' -o' . escapeshellarg($outputfile) . ' ' . escapeshellarg($file); @`$command`; @unlink($file); return $outputfile; } return FALSE; }

Comments

 [2007-11-28 15:14 UTC] jausions (Philippe Jausions)
Thank you for your bug report. This issue has been fixed in the latest released version of the package, which you can download at http://pear.php.net/get/Image_GraphViz