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  


 [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] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!