note 47935 added to function.printer-list
| From: | jt at jtis dot de | Date: | Mon, 06 Dec 2004 11:19:51 +0000 |
| Subject: | note 47935 added to function.printer-list | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81437@lists.php.net to get a copy of this message | ||
As saidyjade mentioned below, printer_list crashes Apache when you pound the resulting array too
much. I don't know why this happens, somebody should look deeper into the subject...
I have found out, contrary to saidyjade, that also just getting the NAME attribute (and remember,
it's case-sensitive! :-) can crash Apache.
Here's what I had:
<?php
foreach (printer_list(PRINTER_ENUM_CONNECTIONS) as $printer)
echo "<option value=\"" . addslashes(strtoupper($printer["NAME"])) .
"\">" . strtoupper($printer["NAME"]) . "\n";
?>
This snippet worked alright, whereas
<?php
foreach (printer_list(PRINTER_ENUM_CONNECTIONS) as $printer)
echo "<option value=\"" . addslashes(strtoupper($printer["NAME"])) .
"\"" . ((strtoupper($printer["NAME"])) ? " selected" :
"") . ">" . strtoupper($printer["NAME"]) . "\n";
?>
crashed Apache everytime the page was loaded.
I played around a bit and found this snippet not crashing:
<?php
foreach (printer_list(PRINTER_ENUM_CONNECTIONS) as $printer)
{
$curprin = strtoupper($printer["NAME"]);
echo "<option value=\"" . addslashes($curprin) . "\"" .
(($curprin == $user["drucker"]) ? " selected" : "") .
">$curprin\n";
}
?>
So, in essence you just need to be careful about how much you use the array and if necessary define
help variables that you can use as much as you want.
Hope this saves somebody some more minutes...
----
Manual Page -- http://www.php.net/manual/en/function.printer-list.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47935
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47935&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47935&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47935&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47935&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47935&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47935&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47935&report=yes
Search -- http://master.php.net/manage/user-notes.php