php-general Digest 1 May 2008 07:55:49 -0000 Issue 5434

Topics (messages 273738 through 273758):

Re: Fun with SOAP.
        273738 by: Larry Brown
        273739 by: Nathan Nobbe

Re: php 5 and mysql failure
        273740 by: Shawn McKenzie
        273741 by: Dan Joseph

check if any element of an array is not "empty"
        273742 by: afan pasalic
        273743 by: Nathan Nobbe
        273744 by: Richard Heyes
        273745 by: afan pasalic
        273746 by: Nathan Nobbe

Re: Best practices for using MySQL index
        273747 by: Chris
        273749 by: Larry Garfield
        273753 by: Shelley
        273754 by: Shelley
        273755 by: Chris

Variable varialbe with array not working
        273748 by: kronostar.aol.com

problem imap_headerinfo
        273750 by: Richard Kurth
        273751 by: Chris
        273752 by: Kalle Sommer Nielsen

equivalent to perl shift function
        273756 by: Richard Luckhurst
        273757 by: Chris
        273758 by: Richard Luckhurst

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 ---
I'm not sure how it looks etc with with soapui but I noticed you
mentioning you don't want to mess with nusoap.  I've used nusoap for
both client and server uses for years and I'm really impressed with how
easily it works.  Using $soapInstance->request and
$soapInstance->response the xml is displayed where you can see how it
was created based on the array you fed the instance before sending for
your message.  It makes troubleshooting much easier for me.

That being said I don't send attachments.  However just doing a quick
google on "nusoap attachments" (without the quotes) has mention of
people sending MIME attachments and one listing an issue with DIME
encoded attachments yet another explaining that he solved the DIME
encoded issue and referred to "wrox book open source webservices page
315" which is an on-line book.

Sorry no quick silver bullet, but I would highly recommend looking at
nusoap if only as a test.

Larry

On Wed, 2008-04-30 at 08:21 -0400, Eric Butera wrote:
> On Wed, Apr 30, 2008 at 7:35 AM, Eric Butera <[EMAIL PROTECTED]> wrote:
> > On Tue, Apr 29, 2008 at 5:07 PM, Nathan Nobbe <[EMAIL PROTECTED]> wrote:
> >  > i know this has nothing to do w/ getting it to work w/ php, eric, but 
> > have
> >  > you tried hitting the service w/ soap ui?
> >  > http://www.soapui.org/
> >  >
> >  > although its written in java, its an indispensable testing tool, imho, 
> > and i
> >  > always give it a shot when im having soap troubles.  i might try to see 
> > if
> >  > you can get a successful response from the service w/ it.
> >  >
> >  > -nathan
> >
> >  Hi Nathan!
> >
> >  Thanks for the reply.  I'm download it as we speak.  Hopefully it'll
> >  give me some sort of answer as to what is going on.  I really haven't
> >  found out enough about the SOAP "standard" enough to know what is
> >  expected behavior, etc.  I know I can see all of the raw data there,
> >  just ext/soap doesn't seem to like the multi-part.  Maybe soapUI will
> >  give me some sort of answer for this.
> >
> 
> After using soapUI I've determined that the SOAP response gives back
> an envelope and has one attachment.  Does anyone know if the SOAP
> extension can handle attachments?  I'd really rather not mess around
> with nusoap or the pear soap package.  I don't see anywhere on the
> manual where it is possible to download attachments.  Hopefully
> someone else has dealt with this before.
> 
-- 
Larry Brown <[EMAIL PROTECTED]>


--- End Message ---
--- Begin Message ---
On Wed, Apr 30, 2008 at 1:53 PM, Larry Brown <
[EMAIL PROTECTED]> wrote:

> Sorry no quick silver bullet, but I would highly recommend looking at
> nusoap if only as a test.
>

additionally, i could not find any occurrence of 'attachment' grepping
through the c code in the soap extension or the rpc extension..

-nathan

--- End Message ---
--- Begin Message ---
Yehudi Alexis Garrett wrote:
I'm using a php script which performs three xml queries to other three servers to retrieve a set of ids and after I do a query to mysql of the kind
SELECT * FROM table WHERE id IN ('set of ids');
Although I'm sure the connection to the database is ok, I sometimes get an error of this kind: *Warning*: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in ...
This does not happen every time i run the script, only sometimes.
If I echo the query, copy and paste in phpmyadmin, or if I perform the same query in a script that does only the query without the rest it works! After troubleshooting this issue I noticed that it usually failed when I had a big set of ids (positive response from more than one server). This means that the script used a bigger amount of memory and probably more resources, but I did not get an "out of memory error", I got the one described bfore.
My question is, is there any kind of limit somewhere in php5 or in mysql?
Thanks for help,

YEHUDI GARRETT

Are you sure that you always pass one or more ids into the query and that at least one of those ids exist in the db?

-Shawn

--- End Message ---
--- Begin Message ---
On Wed, Apr 30, 2008 at 2:31 AM, Yehudi Alexis Garrett <[EMAIL PROTECTED]>
wrote:

> I'm using a php script which performs three xml queries to other three
> servers to retrieve a set of ids and after I do a query to mysql of the kind
> SELECT * FROM table WHERE id IN ('set of ids');
> Although I'm sure the connection to the database is ok, I sometimes get an
> error of this kind:
> *Warning*: mysql_fetch_object(): supplied argument is not a valid MySQL
> result resource in ...
> This does not happen every time i run the script, only sometimes.
> If I echo the query, copy and paste in phpmyadmin, or if I perform the
> same query in a script that does only the query without the rest it works!
> After troubleshooting this issue I noticed that it usually failed when I
> had a big set of ids (positive response from more than one server). This
> means that the script used a bigger amount of memory and probably more
> resources, but I did not get an "out of memory error", I got the one
> described bfore.
> My question is, is there any kind of limit somewhere in php5 or in mysql?
> Thanks for help,
>
> YEHUDI GARRETT
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Have you tried output your SQL query and pasting it into mysql to see if it
runs?  Sounds to me like it isn't a valid query, that would give you that
error.

You may also want to put some row count checking prior to trying to fetch
any rows.

-- 
-Dan Joseph

"Build a man a fire, and he will be warm for the rest of the day.
Light a man on fire, and will be warm for the rest of his life."

--- End Message ---
--- Begin Message ---
hi,
as a result of one calculation I'm receiving an array where elements
could be 0 or date (as string yyyy-mm-dd hh:ii:ss).
I have to check if any of elements of the array is "date" or if all
elements of the array is 0?

If I try array_sum($result) I'll get 0 no matter what (0 + $string = 0).

I know I can do something like:
foreach($result as $value)
{
    if ($value !=0)
    {
       $alert = true;
    }
}

or

if (in_array($result, '-'))
{
    $alert = true;
}


but I was thinking if there is the function does that.

thanks for any help.

-afan

--- End Message ---
--- Begin Message ---
On Wed, Apr 30, 2008 at 2:36 PM, afan pasalic <[EMAIL PROTECTED]> wrote:

> hi,
> as a result of one calculation I'm receiving an array where elements
> could be 0 or date (as string yyyy-mm-dd hh:ii:ss).
> I have to check if any of elements of the array is "date" or if all
> elements of the array is 0?
>
> If I try array_sum($result) I'll get 0 no matter what (0 + $string = 0).
>
> I know I can do something like:
> foreach($result as $value)
> {
>    if ($value !=0)
>    {
>       $alert = true;
>    }
> }
>
> or
>
> if (in_array($result, '-'))
> {
>    $alert = true;
> }
>
>
> but I was thinking if there is the function does that.


i don think theres a function for that; and to be performance conscience, if
just one occurrence of a date is all you need to know its not all 0's then
break out of the loop once youve found that.

foreach($result as $value)
{
   if ($value !== 0)
   {
      $alert = true;
      break;
   }
}

-nathan

--- End Message ---
--- Begin Message ---
but I was thinking if there is the function does that.

array_filter(). Note this:

"If no callback is supplied, all entries of input equal to FALSE (see converting to boolean) will be removed."

http://uk3.php.net/manual/en/function.array-filter.php

--
Richard Heyes

+----------------------------------------+
| Access SSH with a Windows mapped drive |
|    http://www.phpguru.org/sftpdrive    |
+----------------------------------------+

--- End Message ---
--- Begin Message ---
yup! that's the one
:D

thanks richard



Richard Heyes wrote:
>> but I was thinking if there is the function does that.
>
> array_filter(). Note this:
>
> "If no callback is supplied, all entries of input equal to FALSE (see
> converting to boolean) will be removed."
>
> http://uk3.php.net/manual/en/function.array-filter.php
>

--- End Message ---
--- Begin Message ---
On Wed, Apr 30, 2008 at 2:58 PM, Richard Heyes <[EMAIL PROTECTED]> wrote:

> but I was thinking if there is the function does that.
>>
>
> array_filter(). Note this:
>
> "If no callback is supplied, all entries of input equal to FALSE (see
> converting to boolean) will be removed."
>
> http://uk3.php.net/manual/en/function.array-filter.php


i dont really see how that gets him the answer without at least checking the
number of elements in the array after filtering it w/ array_filter; which if
he wanted to reuse in several places would make sense to write a simple
function for anyway..

function isSomethingInArray($array) {
    if(count(array_filter($array)) > 0) { return true; } else { return
false; }
}

-nathan

--- End Message ---
--- Begin Message ---
>> Index on most integer fields only. Text fields can be indexed, but is not
>> important when you design your DB well.
>>
>> Don't index just all integer fields. Keep track of the cardinality of a
>> column. If you expect a field to have 100.000 records, but with only 500
>> distinct values it has no use to put an index on that column. A full record
>> search is quicker.
> 
>    Hmmm... That's new. :)

To explain that further the idea is that if you have something like a
'status' field which can only hold 5 values, there's no point indexing
it if there's a reasonably even spread.

If you could only ever have a handful of fields with a status code of
'1', then it's worth indexing if you have to find those particular
records quickly. I don't think mysql supports partial indexes, but some
databases do so you only index the fields that match a certain criteria.

I'd suggest a more thorough approach to working out what to index rather
than just trying to guess what's going on.

Work out how long queries are taking (either use the mysql slow log or
if you're using a database abstraction class, it should be easy enough
to hack in) and concentrate on those first.

http://www.designmagick.com/article/16/PostgreSQL/How-to-index-a-database

(While it's on a postgresql site, there's nothing specifically for
postgresql in that article - the same rules apply to mysql, oracle, mssql).

--- End Message ---
--- Begin Message ---
On Wednesday 30 April 2008, Chris wrote:
> >> Index on most integer fields only. Text fields can be indexed, but is
> >> not important when you design your DB well.
> >>
> >> Don't index just all integer fields. Keep track of the cardinality of a
> >> column. If you expect a field to have 100.000 records, but with only 500
> >> distinct values it has no use to put an index on that column. A full
> >> record search is quicker.
> >
> >    Hmmm... That's new. :)
>
> To explain that further the idea is that if you have something like a
> 'status' field which can only hold 5 values, there's no point indexing
> it if there's a reasonably even spread.
>
> If you could only ever have a handful of fields with a status code of
> '1', then it's worth indexing if you have to find those particular
> records quickly. I don't think mysql supports partial indexes, but some
> databases do so you only index the fields that match a certain criteria.
>
> I'd suggest a more thorough approach to working out what to index rather
> than just trying to guess what's going on.

Another piece of low-hanging-fruit is to index a field that you will be 
joining on frequently.  Point above about spread still applies, but if you 
can join index to index, the join goes a lot faster.  (A primary key in MySQL 
is always indexed.)  

Having too many indexes rarely if ever costs on read (as far as I am aware), 
but it does cost on write to update the index.  How much that matters is 
use-case specific.

-- 
Larry Garfield                  AIM: LOLG42
[EMAIL PROTECTED]               ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

--- End Message ---
--- Begin Message ---
On Wed, Apr 30, 2008 at 7:03 PM, Aschwin Wesselius <[EMAIL PROTECTED]>
wrote:

>  Shelley wrote:
>
>  Don't index just all integer fields. Keep track of the cardinality of a
> column. If you expect a field to have 100.000 records, but with only 500
> distinct values it has no use to put an index on that column. A full record
> search is quicker.
>
>
>     Hmmm... That's new. :)
>
>
>
> Well, to give you a good measure: keep the cardinality between 30 to 70-80
> percent of your total records in a column. But sometimes your field is NULL
> or empty, so it really depends. You can't just put it into a standard
> configuration. And it also really depends on how many records a table
> contains etc.
>
> Besides that, benchmarking your development environment (you do have one
> do you?) can gives you a good idea on how your hardware and setup performs.
>
I think I missed that part. For I am concerning query, index, and entity
design most of the time.

>
>
> Aschwin Wesselius
>



-- 
Regards,
Shelley

--- End Message ---
--- Begin Message ---
On Thu, May 1, 2008 at 9:54 AM, Larry Garfield <[EMAIL PROTECTED]>
wrote:

> On Wednesday 30 April 2008, Chris wrote:
> > >> Index on most integer fields only. Text fields can be indexed, but is
> > >> not important when you design your DB well.
> > >>
> > >> Don't index just all integer fields. Keep track of the cardinality of
> a
> > >> column. If you expect a field to have 100.000 records, but with only
> 500
> > >> distinct values it has no use to put an index on that column. A full
> > >> record search is quicker.
> > >
> > >    Hmmm... That's new. :)
> >
> > To explain that further the idea is that if you have something like a
> > 'status' field which can only hold 5 values, there's no point indexing
> > it if there's a reasonably even spread.
> >
> > If you could only ever have a handful of fields with a status code of
> > '1', then it's worth indexing if you have to find those particular
> > records quickly. I don't think mysql supports partial indexes, but some
> > databases do so you only index the fields that match a certain criteria.
> >
> > I'd suggest a more thorough approach to working out what to index rather
> > than just trying to guess what's going on.
>
> Another piece of low-hanging-fruit is to index a field that you will be
> joining on frequently.

The fact is, we seldom use join. Because we think it very slow to make it
working on two tables
 with millions of  records. Though we did not try it. :(

> Point above about spread still applies, but if you
> can join index to index, the join goes a lot faster.  (A primary key in
> MySQL
> is always indexed.)
>
How much is the *a lot*? Thanks. :)

>
> Having too many indexes rarely if ever costs on read (as far as I am
> aware),
> but it does cost on write to update the index.  How much that matters is
> use-case specific.
>
> --
> Larry Garfield                  AIM: LOLG42
> [EMAIL PROTECTED]          ICQ: 6817012
>
> "If nature has made any one thing less susceptible than all others of
> exclusive property, it is the action of the thinking power called an idea,
> which an individual may exclusively possess as long as he keeps it to
> himself; but the moment it is divulged, it forces itself into the
> possession
> of every one, and the receiver cannot dispossess himself of it."  --
> Thomas
> Jefferson
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Regards,
Shelley

--- End Message ---
--- Begin Message ---
>> Point above about spread still applies, but if you
>> can join index to index, the join goes a lot faster.  (A primary key in
>> MySQL
>> is always indexed.)
>>
> How much is the *a lot*? Thanks. :)

If it's a unique (including primary) key then orders of magnitude for
millions of rows.

If it's a non-unique key, it depends on how many distinct values there are.

-- 
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
I am trying to use variable variables in an array. ?The last line of code does 
not work. ?More specifically the last variable in the last line of code does 
not work in this setup. ?The array gets created with the appropriate indexes 
however the values are blank. ?I can echo item_value and it contains a string 
by the time it gets to that line. ?If I use text instead of a variable for the 
value it works. ?Is my code wrong or could this be a bug?

The file that is read has the following format:
item_1_name= Dummy Text 1
item_1_price=10
item_1_date=Jan 10-14, 2008

item_2_name=Dummy Text 2
item_2_price=20
item_2_date=Feb 1-5, 2008


<?php
$info = file("info.txt");
 
foreach($info as $line) {
??????? if (substr($line,0,1) != "#" && trim($line) != "") {
??????????????? list($item_name, $item_value) = explode("=", $line);
??????????????????????? if (substr($item_name,6) == "_") {
??????????????????????????????? $item_num = substr($item_name,0,5);
??????????????????????? } else {
??????????????????????????????? $item_num = substr($item_name,0,6);
??????????????????????? }
 
??????????????????????? $item_index = 
str_replace("_","",(strrchr($item_name,"_")));
??????????????????????? ${$item_num}[$item_index] = "$item_value";
??????? }
}
?>

--- End Message ---
--- Begin Message --- I get a *Catchable fatal error*: Object of class stdClass could not be converted to string on this line $mail_head = imap_headerinfo($conn, $i); if I remove it it works fine what would be casing this I really need to read the header. I am using php version 5.2.5

$conn = @imap_open("{" . $bouncer['host'] . ":" . $bouncer['port'] . "/" . $bouncer['mailtype'] . "/notls}" . $bouncer['mailbox'], $bouncer['username'], $bouncer['password']);
    $headers = @imap_headers($conn);
       if ($headers) {
         $email_count = sizeof($headers);
         for($i = 1; $i <= $email_count; $i++) {
              # Check the body against all saved patterns
$mail_head = imap_headerinfo($conn, $i); $mail_body = imap_fetchbody($conn, $i, 1);
               echo "mail head: $mail_head<br>\n";
               echo "mail body: $mail_body<br>\n";


--- End Message ---
--- Begin Message ---
Richard Kurth wrote:
> I get a *Catchable fatal error*: Object of class stdClass could not be
> converted to string  on this line  $mail_head = imap_headerinfo($conn, $i);

RTM.

http://www.php.net/imap_headerinfo

It's an object, not a string.

print_r($mail_head);

--- End Message ---
--- Begin Message ---
Hi Richard

Like Chris replied, then the returned value of imap_headerinfo() is an stdClass object. You can iterate though
all the object properties like this:
$header = '';

foreach($mail_head as $headerbit => $value)
{
   if(empty($value))
   {
       continue;
   }

   $header .= $headerbit . ': ' . $value . "\r\n";
}

and then:
echo $header;

You might wanna change the $headerbit to look abit more readable =)

Cheers,
Kalle

----- Original Message ----- From: "Richard Kurth" <[EMAIL PROTECTED]>
To: "PHP General List" <[EMAIL PROTECTED]>
Sent: Thursday, May 01, 2008 5:05 AM
Subject: [PHP] problem imap_headerinfo


I get a *Catchable fatal error*: Object of class stdClass could not be converted to string on this line $mail_head = imap_headerinfo($conn, $i); if I remove it it works fine what would be casing this I really need to read the header. I am using php version 5.2.5

$conn = @imap_open("{" . $bouncer['host'] . ":" . $bouncer['port'] . "/" . $bouncer['mailtype'] . "/notls}" . $bouncer['mailbox'], $bouncer['username'], $bouncer['password']);
    $headers = @imap_headers($conn);
       if ($headers) {
         $email_count = sizeof($headers);
         for($i = 1; $i <= $email_count; $i++) {
              # Check the body against all saved patterns
$mail_head = imap_headerinfo($conn, $i); $mail_body = imap_fetchbody($conn, $i, 1);
               echo "mail head: $mail_head<br>\n";
               echo "mail body: $mail_body<br>\n";


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





--
No virus found in this incoming message.
Checked by AVG. Version: 7.5.524 / Virus Database: 269.23.7/1408 - Release Date: 30-04-2008 18:10




--- End Message ---
--- Begin Message ---
Hi All

I am in the process of porting a perl script and I am trying to fin out if there
is a php equivalent to the perl shift function? I have been looking at the php
manual and google searching so far with no luck.

  


Regards,
Richard Luckhurst                      



--- End Message ---
--- Begin Message ---
Richard Luckhurst wrote:
> Hi All
> 
> I am in the process of porting a perl script and I am trying to fin out if 
> there
> is a php equivalent to the perl shift function? I have been looking at the php
> manual and google searching so far with no luck.

http://www.php.net/manual/en/function.array-shift.php

-- 
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
Hi Chris,

In perl ther is the concept of @_  which is the list of incoming parameter to a
subroutine. It is possible to have something like

my $sock = shift;

As I understand this the first parameter of the @_ list would be shifted.

I see for array_shift there must be an argument, the array name to shift, while
in perl if the array name is omitted the @_ function list is used. Is ther a php
equivalent to the @_ list or how might I use array_shift to achieve the same
result as in perl?

C> Richard Luckhurst wrote:
>> Hi All
>> 
>> I am in the process of porting a perl script and I am trying to fin out if 
>> there
>> is a php equivalent to the perl shift function? I have been looking at the 
>> php
>> manual and google searching so far with no luck.

C> http://www.php.net/manual/en/function.array-shift.php




Regards,
Richard Luckhurst



--- End Message ---

Reply via email to