php-general Digest 4 Aug 2008 13:30:40 -0000 Issue 5606

Topics (messages 277654 through 277666):

Re: PHP Memory Management
        277654 by: Chacha C

[PHP Header] Right-Click Download in Firefox showing php filename
        277655 by: Will
        277660 by: mike
        277661 by: David Otton

Re: uploading big files with PHP
        277656 by: Catalin Zamfir Alexandru | KIT Software CAZ
        277659 by: mike

PDO prepared statements and LIKE escaping
        277657 by: Larry Garfield
        277658 by: Per Jessen

How to jump into and loop through XML element
        277662 by: Ethan Whitt
        277663 by: Aschwin Wesselius

Store database password outside of public_html folder
        277664 by: Don Don
        277665 by: Jason Pruim

SoapClient and arrays
        277666 by: Marten Lehmann

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 ---
is it possible because you can assign $func = foo and call $func() and it
will call foo(), maybe that its creating an endless loop of assigning the
function to itself?

On Sun, Aug 3, 2008 at 11:17 AM, brian <[EMAIL PROTECTED]> wrote:

> Waynn Lue wrote:
>
>> I've been running the script below:
>>
>> <?php
>>  $appIds = getLotsOfAppIds();
>>  foreach ($appIds as $appId) {
>>    echo "$appId\n";
>>    //echo memory_get_usage() . "\n";
>>    try {
>>      $getBundles = getBundles($appId);
>>      $numBundles = count($registeredBundles);
>>      echo $numBundles . "\n";
>>      continue;
>>    }
>>  }
>> ?>
>>
>> And I get PHP Fatal Error: Allowed Memory Size Exhausted after it runs for
>> a
>> bit.  Looking at the memory usage, it's because $getBundles (an array) is
>> huge, and keeps growing.  What I'm confused by is why setting it to
>> something else in the next iteration of the foreach loop doesn't free the
>> previously allocated array, since there shouldn't be any more references
>> to
>> it.  I've worked around it by explicitly calling unset($getBundles), but
>> just wanted to understand why it's working the way it does.
>>
>>
> Aside from on the 1st iteration, each time getBundles() is called, it
> creates an array within its own scope. Until PHP assigns the returned array
> to $getBundles, there are two in memory. Maybe that's the problem.
>
> I don't know how you can stand naming structures or variables the same as
> functions, btw. That would drive me nuts. Where is this $registeredBundles
> coming from? Perhaps you meant:
>
> $registeredBundles = getBundles($appId);
>
> b
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
http://twit.tv
- What I listen to All Week

--- End Message ---
--- Begin Message ---
I followed some of the examples that was on PHP header()
http://us3.php.net/manual/en/function.header.php

I am trying to have users download a file named 'Setup.msi', however
under a PHP file with the sent header information, the default name to
the user will be 'ApplicationSetup_v1_0.msi' -- I am sending the
recommended header information in the notes. For example in my
'download.php':

$forcename = "ApplicationSetup_v1_0.msi";
$filename = "Setup.msi";

header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream; name=".$forcename);
header("Content-Type: application/octetstream; name=".$forcename);
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));

@readfile($filename);


When I LEFT-CLICK the 'download.php' link in Internet Explorer 6/7 and
Firefox 2/3, it defaults the download name to the variable that I want
it changed to ($forcename). When I RIGHT-CLICK in Internet Explorer
6/7, it also works. However when I RIGHT-CLICK the link in Firefox
2/3, it downloads the file as 'download.php' and not the specified
name and .msi extension (I can still rename to the .msi extension and
it works fine). Am I missing another header or is there known issue
for Firefox right-click "Save Link As..." and default the name to
something else? Or should I contact Firefox on this to get more
information to default the name to something different?

Thanks


-- 
William Frankhouser
WilzDezign
http://www.wilzdezign.com

--- End Message ---
--- Begin Message ---
On 8/3/08, Will <[EMAIL PROTECTED]> wrote:

> @readfile($filename);

You should look into a webserver and instead of using readfile() which
will keep the PHP engine open while it is spoonfeeding the browser,
offload the file to the webserver.

nginx has X-Accel-Redirect (nginx is the best anyway)
Lighttpd has X-Lighttpd-Sendfile (or something)
Apache has mod_sendfile (something like that)

etc.

I don't think it will change the renaming behavior, but it will
offload your PHP engines for normal processing. :)

Basically (you'll have to configure it quick but otherwise) instead of
the readfile($file) you'd be sending another:

header("X-Accel-Redirect: $file"); (you have to configure $file's location)

and that's it. the webserver takes over and PHP is released back to do
other things.

--- End Message ---
--- Begin Message ---
2008/8/4 Will <[EMAIL PROTECTED]>:

> I am trying to have users download a file named 'Setup.msi', however
> under a PHP file with the sent header information, the default name to

> $forcename = "ApplicationSetup_v1_0.msi";
> $filename = "Setup.msi";
>
> header("Content-Type: application/force-download");
> header("Content-Type: application/octet-stream; name=".$forcename);
> header("Content-Type: application/octetstream; name=".$forcename);
> header("Content-Transfer-Encoding: binary");
> header("Content-Length: ".filesize($filename));
>
> @readfile($filename);

Try a variation on this:

header("Content-Type: application/x-msi");
header("Content-Disposition: attachment;
filename=\"ApplicationSetup_v1_0.msi\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize('Setup.msi'));
readfile('Setup.msi');

http://www.mhonarc.org/~ehood/MIME/rfc2183.txt

content-disposition controls what the browser should do with the file
you're sending (open it or save it).
filename suggests what the file should be saved as on the local
system, when downloading as an attachment
content-type is the mime-type of the file you're sending

--- End Message ---
--- Begin Message ---
What are you talking about? I've been able to upload a 4GB file without 
problem. Uploading doesn't depend on memory limit, and this has been a subject 
of debate on the PHP.net Manual (uploading files section, check it out).

-----Original Message-----
From: mike [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 04, 2008 4:07 AM
To: brian
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] uploading big files with PHP

On 8/3/08, brian <[EMAIL PROTECTED]> wrote:

> Also, use set_time_limit(0);

and configure the server and php to accept a decent size, and probably
configure the client to put only chunks at a time right?

otherwise php will hit it's memory limit for the script quite easily i
would assume. so there has to be something that allows it to stream
and keep only so much in the buffer at a time.

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


--- End Message ---
--- Begin Message ---
On 8/3/08, Catalin Zamfir Alexandru | KIT Software CAZ
<[EMAIL PROTECTED]> wrote:

> What are you talking about? I've been able to upload a 4GB file without 
> problem. Uploading doesn't depend on memory limit, and this has been a 
> subject of debate on the PHP.net Manual (uploading files section, check it 
> out).

using the PUT method?

--- End Message ---
--- Begin Message ---
Hi folks.  I am trying to figure out the best way to handle an interesting 
issue in PDO prepared statements.  Consider:

$search = 'mystring';

$stmt = $dbh->prepare("SELECT * FROM mytable WHERE myfield LIKE :myfield");
$stmt->execute(array(':myfield' => $search . '%'));

The above will search for any record whose myfield entry begins with the value 
in $search.  Great.  And because it's a prepared statement, the database 
handles SQL injection protection for us.

According to the manual, that is the correct way of handling LIKE statements:

http://us3.php.net/manual/en/pdo.prepared-statements.php

(See Example #6)

But!  Now consider this:

$search = "100% pure PHP";

When that is run, the % in the literal string will get interpreted by the SQL 
server as another wildcard character.  That is not desired.

IIRC, the way in SQL to circumvent that is to convert "100%" into "100%%".  
However, that does rather defeat the purpose of a prepared statement if I 
have to do my own escaping anyway, does it not?  We also cannot use 
$dbh->quote(), as that is intended for cases where you're building a query 
string directly rather than using a prepared statement.

How do other folks handle this issue?

-- 
Larry Garfield
[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
Larry Garfield wrote:

> IIRC, the way in SQL to circumvent that is to convert "100%" into
> "100%%". However, that does rather defeat the purpose of a prepared
> statement if I have to do my own escaping anyway, does it not? 

Depends on what you perceive the purpose of the prepared statement to
be :-)  In this context, I tend to think of performance only.  Which is
generally why I can't be bothered with prepared statements in php. 


/Per Jessen, Zürich


--- End Message ---
--- Begin Message ---
PHP newbie coming over from Perl.  Been trying to convert some of my Perl
scripts over to PHP5.  I am making a request to Amazon and receiving the
following response.  How can I jump down to the <Item> element and loop
through all the ones that exist.  I have been trying to do this with XML
Simple, but with no success.
Thanks, Ethan

<?xml version="1.0" encoding="UTF-8"?>
<ItemSearchResponse xmlns="
http://webservices.amazon.com/AWSECommerceService/2006-11-14";>
 <OperationRequest>
  <HTTPHeaders>
   <Header Name="UserAgent">
   </Header>
   </HTTPHeaders>
    <RequestId>xxxxxxxxxxxxx</RequestId>
    <Arguments>
     <Argument Name="SearchIndex" Value="Books">
     </Argument>
      <Argument Name="AssociateTag" Value="xxxxxxxxxxx">
      </Argument>
       <Argument Name="Service" Value="AWSECommerceService">
       </Argument>
        <Argument Name="Keywords" Value="Perl">
        </Argument>
         <Argument Name="ResponseGroup" Value="Request,Medium">
         </Argument>
          <Argument Name="Operation" Value="ItemSearch">
          </Argument>
           <Argument Name="AWSAccessKeyId" Value="xxxxxxxxxxxxxxxxxx">
           </Argument>
            <Argument Name="Version" Value="2006-11-14">
            </Argument>
            </Arguments>

<RequestProcessingTime>0.176347017288208</RequestProcessingTime>
            </OperationRequest>
            <Items>
             <Request>
              <IsValid>True</IsValid>
              <ItemSearchRequest>
               <Keywords>Perl</Keywords>
               <ResponseGroup>Medium</ResponseGroup>
               <ResponseGroup>Request</ResponseGroup>
               <SearchIndex>Books</SearchIndex>
              </ItemSearchRequest>
             </Request>
             <TotalResults>1893</TotalResults>
             <TotalPages>190</TotalPages>
             <Item>

--- End Message ---
--- Begin Message ---
Ethan Whitt wrote:
PHP newbie coming over from Perl.  Been trying to convert some of my Perl
scripts over to PHP5.  I am making a request to Amazon and receiving the
following response.  How can I jump down to the <Item> element and loop
through all the ones that exist.  I have been trying to do this with XML
Simple, but with no success.
Thanks, Ethan

Hi,

I'm not that much an XML guru, but I use XSL for most of the XML lookups I need. I agree, it is an extra step, but it keeps the data (XML) and the code (PHP) much more separated.

XSL can make use of the XPath syntax and therefore the selections of the nodes are very easy. I haven't looked into a PHP implementation of XPath or the like (if any exists).

Another step the XSL can do for you is the output formatting (hence the S for Stylesheet) and transformations (some use the XSLT for that, wich is the same in my opinion).

If you have different XSL files, you can have different formatting on the same data.

But anyhow Simple XML should be what it's called after.... Simple....
--

Aschwin Wesselius

/'What you would like to be done to you, do that to the other....'/

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

I've been reading on the internet that is most secure to store your database 
details outside of the public accessible folder.

I am a bit stuck on how to do this.

I've got a folder "db_details" that contains the file "dbdetails" which 
contains the database login info.  I normally include this file in any page 
requiring database connectivity e.g. include_once("db_details/dbdetails.php")

How can I now set this up so that the folder/files for the database are stored 
outside of the public_html folder ?

thanks


      

--- End Message ---
--- Begin Message ---

On Aug 4, 2008, at 7:54 AM, Don Don wrote:

Hi All,

I've been reading on the internet that is most secure to store your database details outside of the public accessible folder.

I am a bit stuck on how to do this.

I've got a folder "db_details" that contains the file "dbdetails" which contains the database login info. I normally include this file in any page requiring database connectivity e.g. include_once("db_details/dbdetails.php")

How can I now set this up so that the folder/files for the database are stored outside of the public_html folder ?


Hi Don,

Basically you move it 1 level above the root of your website. So if your website root is: /www/public_html you would put it here: /www/ db_details and then set your include path with:
<?PHP
ini_set("include_path","/path/to/www/db_details:/path/to/other/include/ folders");
?>

and just do that at the top of each page that needs to reference any of your included files and you'll be all set. Personally I use a file called defaults.php that has alot of that type of stuff in it. References to where I keep things, system wide variables things like that.

Works out quite well and no one has told me I'm doing it wrong yet :)



--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
11287 James St
Holland, MI 49424
www.raoset.com
[EMAIL PROTECTED]





--- End Message ---
--- Begin Message ---
Hello,

I'm calling a webservice that is described by a WSDL-URL using the PHP-builtin Soap client. This works fine in general. But although the response is received correct, the variable type is wrong.

According to the WSDL file, the response is defined like this:

<s:element name="SaveResponse">
  <s:complexType>
    <s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="SaveResult" type="s:boolean" />
      <s:element minOccurs="0" maxOccurs="1" name="key" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="messages" type="tns:ArrayOfMessage" />
    </s:sequence>
  </s:complexType>
</s:element>

This pice of code:

print gettype($response). "\n";
var_dump($response);
print $response["key"]. "\n";

returns this:

object
object(stdClass)#2 (3) {
  ["SaveResult"]=>
  bool(true)
  ["key"]=>
  string(52) "FGLHRQXVDQJXQAWBCGJWNCQKTOYFGGMJSHYQELJPSABDGUNZWBEA"
  ["messages"]=>
  object(stdClass)#3 (0) {
  }
}

Fatal error: Cannot use object of type stdClass as array in /whatever/soap.php on line 26

You can see the structure of an associative array. But PHP doesn't treat it as an array. Now with the following code, it works fine:

settype($response, "array");
print gettype($response). "\n";
var_dump($response);
print $response["key"]. "\n";

This returns:

array
array(3) {
  ["SaveResult"]=>
  bool(true)
  ["key"]=>
  string(50) "FGLHRQXWDWKHQPWRDCKSNYRGUKZBHCNFSXZHENMTVKEHJZQPYZ"
  ["messages"]=>
  object(stdClass)#3 (0) {
  }
}
FGLHRQXWDWKHQPWRDCKSNYRGUKZBHCNFSXZHENMTVKEHJZQPYZ

But it seems a bit unhandy and a workaround, if I have to the settype() thing each time I call a webservice. Is there a simpler way?

Regards
Marten

--- End Message ---

Reply via email to