php-general Digest 24 Dec 2008 11:08:30 -0000 Issue 5863
Topics (messages 285023 through 285036):
Re: Segmentation fault in php5-imap
285023 by: Nathan Nobbe
285026 by: Dan Osipov
285028 by: Nathan Nobbe
Re: Help with a Search Function
285024 by: Ashley Sheridan
Re: Assignment (Was Re: [PHP] More microptimisation (Was Re: [PHP] Variable as
an index)
285025 by: Clancy
MERRY XMAS
285027 by: German Geek
285029 by: Nathan Nobbe
285031 by: Robert Cummings
285032 by: Dotan Cohen
285033 by: Kastner Mario
285034 by: Robert Cummings
285036 by: Richard Heyes
Re: Configuring interfaces through php
285030 by: Nathan Nobbe
Re: Create PHP form from MySQL table structure
285035 by: Ronnie MacGregor
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
On Tue, Dec 23, 2008 at 1:42 PM, Dan Osipov <[email protected]> wrote:
> Everything matches. The only thing that's different is that the server
> that's having the problem has been running the script every 15 mins for the
> past 2 months - which leads me to believe there might be a memory leak
> somewhere...
if the script isnt long running, *theorectically* speaking once php shuts
down, all php allocated memory should get freed up, unless theres a bigger
mem leak issue w/ php itself.
Although complete recompiling should reset something, right?
well if you were running an older version of php, and you upgraded to 5.2.8,
then theres a chance a mem leak bug could be fixed by it. but only if they
actually patched that problem. id be surprised to see a memory leak persist
after a php script has run to completion.
I found this:
> http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=502996
> But the patch didn't work. The library is required by php5-imap (which is a
> standalone package).
hmm, so the extension wouldnt compile w/ the patch, or after building w/ the
patch the problem persists?
are you by chance running anything like xdebug on the server. that (and
similar extensions) keep a lot of things in memory during script execution
that php normally cleans up. once i had a cli script which would eat up all
of the memory on the box. even unset() calls wouldnt stop the madness.
then i realized i had xdebug running, disabled it, and bam, all was good
again.
also, do you have any idea, the duration of the script execution.
-nathan
--- End Message ---
--- Begin Message ---
Script takes about 5 minutes to run (average). On other servers I've
seen it run over 2 hours without segfaults... All depends on how many
messages are in the NNTP mailboxes.
After applying the mentioned patch to libc-client2002edebian the issue
persisted. No change...
I'm not running xdebug. The PHP memory limit is 512 Mb and server has
16Gb of RAM, so it doesn't look like its exhausting all the memory,
although one of the libraries potentially could?
If this helps: It looks like the script is dropping connection to the
NNTP server. If it then tries to open another mailbox, it segfaults.
Otherwise it continues to run successfully. But why does it drop the
connection?
Thanks a lot for your help!!
Dan
Nathan Nobbe wrote:
On Tue, Dec 23, 2008 at 1:42 PM, Dan Osipov <[email protected]> wrote:
Everything matches. The only thing that's different is that the server
that's having the problem has been running the script every 15 mins for the
past 2 months - which leads me to believe there might be a memory leak
somewhere...
if the script isnt long running, *theorectically* speaking once php shuts
down, all php allocated memory should get freed up, unless theres a bigger
mem leak issue w/ php itself.
Although complete recompiling should reset something, right?
well if you were running an older version of php, and you upgraded to 5.2.8,
then theres a chance a mem leak bug could be fixed by it. but only if they
actually patched that problem. id be surprised to see a memory leak persist
after a php script has run to completion.
I found this:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=502996
But the patch didn't work. The library is required by php5-imap (which is a
standalone package).
hmm, so the extension wouldnt compile w/ the patch, or after building w/ the
patch the problem persists?
are you by chance running anything like xdebug on the server. that (and
similar extensions) keep a lot of things in memory during script execution
that php normally cleans up. once i had a cli script which would eat up all
of the memory on the box. even unset() calls wouldnt stop the madness.
then i realized i had xdebug running, disabled it, and bam, all was good
again.
also, do you have any idea, the duration of the script execution.
-nathan
--- End Message ---
--- Begin Message ---
On Tue, Dec 23, 2008 at 5:30 PM, Dan Osipov <[email protected]> wrote:
> Script takes about 5 minutes to run (average). On other servers I've seen
> it run over 2 hours without segfaults... All depends on how many messages
> are in the NNTP mailboxes.
ok, so this is def a long running script then.
After applying the mentioned patch to libc-client2002edebian the issue
> persisted. No change...
ok, lets check that one off the list then.
> I'm not running xdebug. The PHP memory limit is 512 Mb and server has 16Gb
> of RAM, so it doesn't look like its exhausting all the memory, although one
> of the libraries potentially could?
ok, i didnt think so, but just wanted to make sure so as not to waste time,
when it could be an easy fix like that.
> If this helps: It looks like the script is dropping connection to
the NNTP server. If it then tries to open another mailbox, it segfaults.
> Otherwise it continues to run successfully.
hmm, well, i dont see any sort of functions in the imap api that check the
integriy of the imap stream. its sounds lame, but have you considered
tearing down and rebuilding the connection after a fixed number of downloads
have completed.
> But why does it drop the connection?
maybe php's client code just wasnt designed to hold imap connections open
for a long periods of time. not sure though.
-nathan
--- End Message ---
--- Begin Message ---
On Tue, 2008-12-23 at 16:14 -0600, Terion Miller wrote:
> Hey Everyone, been steaming right along for a couple days but now I'm stuck
> on writing a search function, could you all take a look at it and see what
> it could be, I will mark the line throwing the error in red, I did try just
> commenting out that line and searching for a record by OrderID that I know
> is there but it does not return anything , I am trying to search several
> tables in one db:
>
> Code:
> <?php
> session_start();
> include("inc/dbconn_open.php");
>
> if (empty($_SESSION['AdminLogin']) OR $_SESSION['AdminLogin'] <> 'OK' ){
> header ("Location: LogOut.php");
> }
>
> if (isset($_GET['AdminID']) && !empty($_GET['AdminID'])){
> $AdminID = $_GET['AdminID'];
> } elseif (isset($_POST['AdminID']) && !empty($_POST['AdminID'])){
> $AdminID = $_POST['AdminID'];
> } else {
> header ("Location: LogOut.php");
> }
>
> $query = "SELECT SearchWorkOrder FROM admin WHERE AdminID='$AdminID'";
> $result = mysql_query ($query);
> $row = mysql_fetch_object ($result);
> if ($row->SearchWorkOrder == "NO") {
> header ("Location:
> Welcome.php?AdminID='.$_SESSION[AdminLogin]'&msg=Sorry, you do not have
> access to that page.");
> }
>
> if (isset($_POST['WorkOrderID'])) {$WorkOrderID = $_POST['WorkOrderID'];}
> else {$WorkOrderID = '';}
> if (isset($_POST['WorkOrderName'])) {$WorkOrderName =
> $_POST['WorkOrderName'];} else {$WorkOrderName = '';}
> if (isset($_POST['CustomerName'])) {$CustomerName = $_POST['CustomerName'];}
> else {$CustomerName = '';}
> if (isset($_POST['CustomerEmail'])) {$CustomerEmail =
> $_POST['CustomerEmail'];} else {$CustomerEmail = '';}
> if (isset($_POST['SalesRep'])) {$SalesRep = $_POST['SalesRep'];} else
> {$SalesRep = '';}
> if (isset($_POST['SalesRepEmail'])) {$SalesRepEmail =
> $_POST['SalesRepEmail'];} else {$SalesRepEmail = '';}
>
> if (isset($_POST['SortBy'])) {$SortBy = $_POST['SortBy'];} else {$SortBy =
> 'WorkOrderID DESC';}
> if (isset($_POST['Page'])) {$Page = $_POST['Page'];} else {$Page = 1;}
>
> $PerPage = 30;
> $StartPage = ($Page - 1) * $PerPage;
> $OrderID = '';
>
>
> // All Orders
> $sql = "SELECT WorkOrderID FROM workorders WHERE WorkOrderID <>'' ";
> if (!empty($WorkOrderName)) {
> $sql .= "AND Advertiser LIKE '%". $WorkOrderName ."%' ";
> }
> if (!empty($WorkOrderID)) {
> $sql .= "AND WorkOrderID LIKE '%". $WorkOrderID ."%' ";
> }
> $result = mysql_query ($sql);
> while ($row = mysql_fetch_object ($result)) {
> $OrderID = $OrderID .", ". $row->WorkOrderID;
> }
>
>
>
> // Work Orders
> if (!empty($CustomerName) || !empty($CustomerEmail) || !empty($SalesRep)
> || !empty($SalesRepEmail)) {
> $sql = "SELECT WorkOrderID FROM workorderform WHERE WorkOrderID<>''
> ";
> if (!empty($CustomerName)) {
> $sql .= "AND Advertiser LIKE '%". $CustomerName ."%' ";
> }
> if (!empty($CustomerEmail)) {
> $sql .= "AND AdContactEmail LIKE '%". $CustomerEmail ."%' ";
> }
> if (!empty($SalesRep)) {
> $sql .= "AND Salesperson LIKE '%". $SalesRep ."%' ";
> }
> if (!empty($SalesRepEmail)) {
> $sql .= "AND SalespersonEmail LIKE '%". $SalesRepEmail ."%' ";
> }
> $result = mysql_query ($sql);
> while ($row = mysql_fetch_object ($result)) {
> $OrderID = $OrderID .", ". $row->WorkOrderID;
> }
> }
>
> // Homescape Builder Profile
> if (!empty($CustomerName) || !empty($CustomerEmail) || !empty($SalesRep)
> || !empty($SalesRepEmail)) {
> $sql = "SELECT WorkOrderID FROM hs_builder_profile WHERE
> WorkOrderID<>'' ";
> if (!empty($CustomerName)) {
> $sql .= "AND OrganizationName LIKE '%". $CustomerName ."%' ";
> }
> if (!empty($CustomerEmail)) {
> $sql .= "AND LeadEmail LIKE '%". $CustomerEmail ."%' ";
> }
> if (!empty($SalesRep)) {
> $sql .= "AND Salesperson LIKE '%". $SalesRep ."%' ";
> }
> if (!empty($SalesRepEmail)) {
> $sql .= "AND SalespersonEmail LIKE '%". $SalesRepEmail ."%' ";
> }
> $result = mysql_query ($sql);
> while ($row = mysql_fetch_object ($result)) {
> $OrderID = $OrderID .", ". $row->WorkOrderID;
> }
> }
>
> // Homescape Builder Spec Home
> if (!empty($CustomerName) || !empty($SalesRep) ||
> !empty($SalesRepEmail)) {
> $sql = "SELECT WorkOrderID FROM hs_spec_home WHERE WorkOrderID<>''
> ";
> if (!empty($CustomerName)) {
> $sql .= "AND CommunityName LIKE '%". $CustomerName ."%' ";
> }
> if (!empty($SalesRep)) {
> $sql .= "AND Salesperson LIKE '%". $SalesRep ."%' ";
> }
> if (!empty($SalesRepEmail)) {
> $sql .= "AND SalespersonEmail LIKE '%". $SalesRepEmail ."%' ";
> }
> $result = mysql_query ($sql);
> while ($row = mysql_fetch_object ($result)) {
> $OrderID = $OrderID .", ". $row->WorkOrderID;
> }
> }
>
> // Planet Discover Coupon
> if (!empty($CustomerName) || !empty($SalesRep) ||
> !empty($SalesRepEmail)) {
> $sql = "SELECT WorkOrderID FROM pd_coupon WHERE WorkOrderID<>'' ";
> if (!empty($CustomerName)) {
> $sql .= "AND BusinessName LIKE '%". $CustomerName ."%' ";
> }
> if (!empty($SalesRep)) {
> $sql .= "AND Salesperson LIKE '%". $SalesRep ."%' ";
> }
> if (!empty($SalesRepEmail)) {
> $sql .= "AND SalespersonEmail LIKE '%". $SalesRepEmail ."%' ";
> }
> $result = mysql_query ($sql);
> while ($row = mysql_fetch_object ($result)) {
> $OrderID = $OrderID .", ". $row->WorkOrderID;
> }
> }
>
> // Planet Discover Enhanced Listing
> if (!empty($CustomerName) || !empty($CustomerEmail) || !empty($SalesRep)
> || !empty($SalesRepEmail)) {
> $sql = "SELECT WorkOrderID FROM pd_enhanced WHERE WorkOrderID<>'' ";
> if (!empty($CustomerName)) {
> $sql .= "AND BusinessName LIKE '%". $CustomerName ."%' ";
> }
> if (!empty($CustomerEmail)) {
> $sql .= "AND Email LIKE '%". $CustomerEmail ."%' ";
> }
> if (!empty($SalesRep)) {
> $sql .= "AND Salesperson LIKE '%". $SalesRep ."%' ";
> }
> if (!empty($SalesRepEmail)) {
> $sql .= "AND SalespersonEmail LIKE '%". $SalesRepEmail ."%' ";
> }
> $result = mysql_query ($sql);
> while ($row = mysql_fetch_object ($result)) {
> $OrderID = $OrderID .", ". $row->WorkOrderID;
> }
> }
>
> // Planet Discover Right Side Text Ad
> if (!empty($CustomerName) || !empty($SalesRep) ||
> !empty($SalesRepEmail)) {
> $sql = "SELECT WorkOrderID FROM pd_textad WHERE WorkOrderID<>'' ";
> if (!empty($CustomerName)) {
> $sql .= "AND Customer LIKE '%". $CustomerName ."%' ";
> }
> if (!empty($SalesRep)) {
> $sql .= "AND Salesperson LIKE '%". $SalesRep ."%' ";
> }
> if (!empty($SalesRepEmail)) {
> $sql .= "AND SalespersonEmail LIKE '%". $SalesRepEmail ."%' ";
> }
> $result = mysql_query ($sql);
> while ($row = mysql_fetch_object ($result)) {
> $OrderID = $OrderID .", ". $row->WorkOrderID;
> }
> }
>
> if (substr($OrderID, -2) == ", ") {
> $OrderID = substr($OrderID, 0, -2);
> }
>
> if (substr($OrderID, 0, 2) == ", ") {
> $OrderID = substr($OrderID, 2);
> }
>
>
> $sql = "SELECT WorkOrderID FROM workorders WHERE WorkOrderID IN
> ($OrderID)";
> $result = mysql_query ($sql);
> * $Total = ceil(mysql_num_rows($result)/$PerPage);
> *
> $sql = "SELECT WorkOrderID, DATE_FORMAT(CreatedDate,'%m/%e/%y') AS
> SubmitDate, Location, AdminID, FormName, Status FROM ";
> $sql .= "workorders WHERE WorkOrderID IN ($OrderID) ORDER BY $SortBy
> LIMIT $StartPage, $PerPage";
> $result = mysql_query ($sql);
>
>
> If ($Page > 0) {$PagePrev = ($Page - 1);} else {$PagePrev = '';}
> If ($Page < $Total) {$PageNext = ($Page + 1);} else {$PageNext = '';}
> ?>
>
> the error is this one: *Warning*: mysql_num_rows(): supplied argument is not
> a valid MySQL result resource in *
> C:\Inetpub\Xampp\htdocs\SNLeader\WOSystemN\ViewOrders.php* on line *182
>
> Thanks in advance
> *
Have you determined whether the problem is with your queries or the PHP?
Try printing out the queries and then running those in phpMyAdmin.
Ash
www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On Tue, 23 Dec 2008 10:25:13 -0500, [email protected] (tedd) wrote:
>At 9:10 AM +1100 12/23/08, Clancy wrote:
>>Schlossnagle (in "Advanced PHP Programming") advises:
>>
>>$i = 0; while ($i < $j)
>> {
>> ........
>> ++$i;
>> }
>>
>>rather than:
>>
>>$i = 0; while ($i < $j)
>> {
>> .......
>> $i++;
>> }
>>
>>as the former apparently uses less memory references. However I
>>find it very hard to
>
>Two things:
>
>1. One statement, one line.
>2. The code between the two examples is different; produces different
>results; and thus is rather pointless in making a definitive
>comparison.
>
>Assignment, demonstrate a correct way to test ++i vs i++.
>
>Cheers,
>
>tedd
Spoken like a true demagogue -- nitpicking about trivial points of style, but
displaying
total ignorance of elementary rules of programming.
One of the things I like about Schlossnagle's book is that he gives commonsense
advice.
Specifically he advises against obsessing about other people's style rules, but
suggests
that you choose a style that you like, and use it consistently.
And as the examples are written they do exactly the same thing; they each go
through the
empty loop $j times. I had rashly assumed that anyone reading this discussion
group would
understand that they were shorthand for something like the following:
$i = 0; while ($i < $j)
{
If ($a[$i])
{
[ some operation involving $i]
}
$i++;
}
$i cannot be incremented at the start as it is used inside the conditional
expression, nor
can it be implemented inside the expression or you would get an infinite loop
the first
time you missed it, so it has to be incremented at the end of the loop, and it
is
immaterial whether you choose ++$i; or $i++;
Clancy
--- End Message ---
--- Begin Message ---
Merry xmas to everyone! Thanks for the support and fun discussions.
Regards,
Tim
Tim-Hinnerk Heuer
http://www.ihostnz.com
--- End Message ---
--- Begin Message ---
On Tue, Dec 23, 2008 at 8:59 PM, German Geek <[email protected]> wrote:
> Merry xmas to everyone! Thanks for the support and fun discussions.
word
--- End Message ---
--- Begin Message ---
On Wed, 2008-12-24 at 00:38 -0700, Nathan Nobbe wrote:
> On Tue, Dec 23, 2008 at 8:59 PM, German Geek <[email protected]> wrote:
>
> > Merry xmas to everyone! Thanks for the support and fun discussions.
As they say in my son's kindergarten so as to be all inclusive:
We wish you a happy holiday!
We wish you a happy holiday!
We wish you a happy holiday,
and a happy New Year!!
:)
Although, I guess that's a bit half baked if you're working through the
"holidays" :/
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
2008/12/24 German Geek <[email protected]>:
> Merry xmas to everyone! Thanks for the support and fun discussions.
>
חג חנוכה שמח!
Happy Hanuka to those who celebrate it!
--
Dotan Cohen
http://what-is-what.com
http://gibberish.co.il
א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
ا-ب-ت-ث-ج-ح-خ-د-ذ-ر-ز-س-ش-ص-ض-ط-ظ-ع-غ-ف-ق-ك-ل-م-ن-ه-و-ي
А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я
ä-ö-ü-ß-Ä-Ö-Ü
--- End Message ---
--- Begin Message ---
Merry XMas from Austria out to the world!
Love to everyone
Mario
http://unite-it.at
<?php
function celebrateChristmas(array $people)
{
foreach ($people as $individuum)
{
printf("Wish you a merry Xmas, %s", $individuum);
}
singSomeChristmasCarols();
drinkSomeEggNog($dringToMuch = false);
// sendBillGatesAxMasEmail();
// ...
}
?>
--- End Message ---
--- Begin Message ---
On Wed, 2008-12-24 at 09:43 +0100, Kastner Mario wrote:
> Merry XMas from Austria out to the world!
>
> Love to everyone
> Mario
>
> http://unite-it.at
>
> <?php
> function celebrateChristmas(array $people)
> {
> foreach ($people as $individuum)
> {
> printf("Wish you a merry Xmas, %s", $individuum);
Lol, I like individuum.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
> word
Which one?
Happpy needless turkey murder day! To coin a phrase.
--
Richard Heyes
HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated December 20th)
--- End Message ---
--- Begin Message ---
On Wed, Dec 24, 2008 at 12:36 AM, Heysem Kaya
<[email protected]>wrote:
> Hi Nathan,
>
> Thanks for your response. Is there such a way to reconfigure the interface
> IP,dns and gateway as well?
>
please keep responses on-list, so that others may benefit.
yes, you can do anything (almost?) you can on the cli w/ those exec family
of calls. so, basic *nix stuff, sprinkled w/ some php if you want to have
more dynamic code..
...
$ifconfigUpOutput = shell_exec("/sbin/ifconfig $interface netmask $netmask
broadcast $broadcast up");
$defaultRoute = shell_exec("route add default gw $defaultGw");
file_put_contents('/etc/resolv.conf', $nameserList);
...
something to that effect. just bear in mind what could happen if network
connectivity doesnt come back up, etc, etc.
-nathan
--- End Message ---
--- Begin Message ---
On Tue, 23 Dec 2008 06:38:29 -0600
Jay Blanchard said :
> Here is a quick and dirty function that I have used for a couple of
> years now, complete with comments;
>
> function formCreate($database, $table, $action, $excludeCols, $recordID){
Jay
This function is very good for creating the contents of a basic form.
Can I just confirm that the form population by passing $recordID has still to
be implemented. I can see no evidence of this parameter being used.
Thanks,
Ronnie
--
Ronnie MacGregor
Scotland
Ronnie at
dBASEdeveloper
dot co dot uk
www.dBASEdeveloper.co.uk
--- End Message ---