php-general Digest 9 Feb 2010 21:05:38 -0000 Issue 6582

Topics (messages 301897 through 301912):

Re: howto do informative error handling without the fatalities
        301897 by: Rene Veerman
        301898 by: Teus Benschop
        301899 by: Nathan Rixham
        301900 by: Richard Quadling
        301901 by: Richard
        301902 by: Richard Quadling
        301903 by: Richard
        301904 by: Robert Cummings
        301905 by: Ashley Sheridan
        301906 by: Robert Cummings
        301908 by: Richard Quadling
        301910 by: Richard

create archive file in memory with zipArchive class
        301907 by: Ryan Sun
        301909 by: Richard Quadling
        301911 by: Ryan Sun

SOAP connect error
        301912 by: Eric Lommatsch

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
I would also like to hear suggestions on how to fix this mess:

$r = funcA ( funcB ( funcC ( $p ) ) );

if funcB() / funcC() fails, how would you fudge/abort the calling
function in the chain?
One may think that funcA and funcB just check their parameters list
for being "error" arrays, but the problem i foresee is that depending
on the context of the $r= call, desired behaviour may vary at any
stage in the funcA -> funcB -> funcC chain.

--- End Message ---
--- Begin Message ---
On Tue, 2010-02-09 at 07:22 +0100, Rene Veerman wrote:
> I would also like to hear suggestions on how to fix this mess:
> 
> $r = funcA ( funcB ( funcC ( $p ) ) );
> 
> if funcB() / funcC() fails, how would you fudge/abort the calling
> function in the chain?
> One may think that funcA and funcB just check their parameters list
> for being "error" arrays, but the problem i foresee is that depending
> on the context of the $r= call, desired behaviour may vary at any
> stage in the funcA -> funcB -> funcC chain.
> 
I would abort it by embedding the mess in a try.. catch statement, then
throwing an exception. Teus.

--- End Message ---
--- Begin Message ---
Rene Veerman wrote:
> Hi,
> 
> I'm looking for a strategy to do informative error handling at all
> levels of my code, yet keep these errors non-fatal as often as
> possible.

error_log - for logging errors
throw Exception - for show stoppers
try/catch - for when you can handle a potential show stopper

custom error logging / messaging can easily be achieved with something
like this:

<?php

class Messenger
{

  private static $_messages = array();

  public static function addMessage( $string )
  {
    self::$_messages[] = $string;
    if( $string instanceof Exception ) {
      echo self::report();
    }
  }

  public static function report()
  {
    return implode( PHP_EOL , self::$_messages );
  }

}

set_exception_handler( 'Messenger::addMessage' );

Messenger::addMessage( 'little error report 1' );
Messenger::addMessage( 'little error report 2' );
Messenger::addMessage( 'little error report 3' );
throw new Exception( 'this will stop the script' );
// exception will kill the script; if you comment it out
// or wrap it in a try catch then you can keep going..
Messenger::addMessage( 'little error report 4' );
// try catch exceptions and report them like this..
try {
  throw new Exception( 'we could catch this' );
} catch ( Exception $e ) {
  Messenger::addMessage( $e );
}
Messenger::addMessage( 'little error report 5' );
// and when your done just echo it out or save it or..
echo Messenger::report();


Regards!

--- End Message ---
--- Begin Message ---
On 9 February 2010 11:48, Nathan Rixham <nrix...@gmail.com> wrote:
> Rene Veerman wrote:
>> Hi,
>>
>> I'm looking for a strategy to do informative error handling at all
>> levels of my code, yet keep these errors non-fatal as often as
>> possible.
>
> error_log - for logging errors
> throw Exception - for show stoppers
> try/catch - for when you can handle a potential show stopper
>
> custom error logging / messaging can easily be achieved with something
> like this:
>
> <?php
>
> class Messenger
> {
>
>  private static $_messages = array();
>
>  public static function addMessage( $string )
>  {
>    self::$_messages[] = $string;
>    if( $string instanceof Exception ) {
>      echo self::report();
>    }
>  }
>
>  public static function report()
>  {
>    return implode( PHP_EOL , self::$_messages );
>  }
>
> }
>
> set_exception_handler( 'Messenger::addMessage' );
>
> Messenger::addMessage( 'little error report 1' );
> Messenger::addMessage( 'little error report 2' );
> Messenger::addMessage( 'little error report 3' );
> throw new Exception( 'this will stop the script' );
> // exception will kill the script; if you comment it out
> // or wrap it in a try catch then you can keep going..
> Messenger::addMessage( 'little error report 4' );
> // try catch exceptions and report them like this..
> try {
>  throw new Exception( 'we could catch this' );
> } catch ( Exception $e ) {
>  Messenger::addMessage( $e );
> }
> Messenger::addMessage( 'little error report 5' );
> // and when your done just echo it out or save it or..
> echo Messenger::report();
>
>
> Regards!
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

I have extended the standard exception class to send me an email
whenever an exception occurs.

I treat all errors on the live system as exceptions. They shouldn't
occur. If they do, I've missed something.

But at least I'll get a near instant notification of the issue, along
with the stack and all the params involved.

Very useful.



-- 
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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

> I have extended the standard exception class to send me an email
> whenever an exception occurs.

I did that once. Once being the operative word... :-) Ended up with
tens of thousands of emails one morning. At first I thought... "Wow,
maybe my popularity has grown somewhat". But it hadn't.

-- 
Richard Heyes
HTML5 canvas graphing: RGraph - http://www.rgraph.net (updated 31st January)
Lots of PHP and Javascript code - http://www.phpguru.org

--- End Message ---
--- Begin Message ---
On 9 February 2010 12:55, Richard <rich...@php.net> wrote:
> Hi,
>
>> I have extended the standard exception class to send me an email
>> whenever an exception occurs.
>
> I did that once. Once being the operative word... :-) Ended up with
> tens of thousands of emails one morning. At first I thought... "Wow,
> maybe my popularity has grown somewhat". But it hadn't.
>
> --
> Richard Heyes
> HTML5 canvas graphing: RGraph - http://www.rgraph.net (updated 31st January)
> Lots of PHP and Javascript code - http://www.phpguru.org
>

But I bet you REALLY quickly fixed the problem!

Oh. BTW. Thanks for RMail (previously known as htmlmimemail5 if anyone
else is interested).



-- 
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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

> But I bet you REALLY quickly fixed the problem!

I just took out the error handling. :-)

-- 
Richard Heyes
HTML5 canvas graphing: RGraph - http://www.rgraph.net (updated 7th February)
Lots of PHP and Javascript code - http://www.phpguru.org

--- End Message ---
--- Begin Message ---
Richard wrote:
Hi,

I have extended the standard exception class to send me an email
whenever an exception occurs.

I did that once. Once being the operative word... :-) Ended up with
tens of thousands of emails one morning. At first I thought... "Wow,
maybe my popularity has grown somewhat". But it hadn't.

I have something similar... a cron job that checks the error_log file every 10 minutes and sends me the contents if any exist. I also set a special header so I can be sure it's not spam and appropriately route it into my mail folder maze, Much less spammy :)

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
On Tue, 2010-02-09 at 09:19 -0500, Robert Cummings wrote:

> Richard wrote:
> > Hi,
> > 
> >> I have extended the standard exception class to send me an email
> >> whenever an exception occurs.
> > 
> > I did that once. Once being the operative word... :-) Ended up with
> > tens of thousands of emails one morning. At first I thought... "Wow,
> > maybe my popularity has grown somewhat". But it hadn't.
> 
> I have something similar... a cron job that checks the error_log file 
> every 10 minutes and sends me the contents if any exist. I also set a 
> special header so I can be sure it's not spam and appropriately route it 
> into my mail folder maze, Much less spammy :)
> 
> Cheers,
> Rob.
> -- 
> http://www.interjinn.com
> Application and Templating Framework for PHP
> 


Real developers don't have errors in their code; they're undocumented
features ;)

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Ashley Sheridan wrote:
On Tue, 2010-02-09 at 09:19 -0500, Robert Cummings wrote:

Richard wrote:
Hi,

I have extended the standard exception class to send me an email
whenever an exception occurs.
I did that once. Once being the operative word... :-) Ended up with
tens of thousands of emails one morning. At first I thought... "Wow,
maybe my popularity has grown somewhat". But it hadn't.
I have something similar... a cron job that checks the error_log file every 10 minutes and sends me the contents if any exist. I also set a special header so I can be sure it's not spam and appropriately route it into my mail folder maze, Much less spammy :)

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP



Real developers don't have errors in their code; they're undocumented
features ;)

Hmmmm... I've always gone with "a wise man learns from his mistakes".

Not that I'm saying I'm wise or anything... just seems a good goal to shoot for :)

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
On 9 February 2010 14:20, Ashley Sheridan <a...@ashleysheridan.co.uk> wrote:
>
> On Tue, 2010-02-09 at 09:19 -0500, Robert Cummings wrote:
>
> Richard wrote:
> > Hi,
> >
> >> I have extended the standard exception class to send me an email
> >> whenever an exception occurs.
> >
> > I did that once. Once being the operative word... :-) Ended up with
> > tens of thousands of emails one morning. At first I thought... "Wow,
> > maybe my popularity has grown somewhat". But it hadn't.
>
> I have something similar... a cron job that checks the error_log file
> every 10 minutes and sends me the contents if any exist. I also set a
> special header so I can be sure it's not spam and appropriately route it
> into my mail folder maze, Much less spammy :)
>
> Cheers,
> Rob.
> --
> http://www.interjinn.com
> Application and Templating Framework for PHP
>
>
> Real developers don't have errors in their code; they're undocumented 
> features ;)
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>

So, no documentation AND bugs!!! Gee. I really wouldn't want to rely
on that code base!

--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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

>> Real developers don't have errors in their code; they're undocumented 
>> features ;)

Or alternatively, if you freelance - "Forthcoming employment opportunities" :-)

-- 
Richard Heyes
HTML5 canvas graphing: RGraph - http://www.rgraph.net (updated 7th February)
Lots of PHP and Javascript code - http://www.phpguru.org

--- End Message ---
--- Begin Message ---
I want to generate credential zip file for user on the fly with
zipArchive and render it for download, so I created following code
---------------------------------------------------------
$zip = new ZipArchive();
$filename = '/tmp/xxx.zip';
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
     throw new Exception();
}
if($zip)
{
    $zip->addFromString('xxx.xx', $fileString);
}
$zip->close();
$fileString = file_get_contents($filename);
unlink($filename);

$this->getResponse()->setHeader('Content-Type', 'application/zip');
$this->getResponse()->setHeader('Content-Disposition','attachment;filename=xxx.zip');
$this->getResponse()->setBody($fileString);
-----------------------------------------------------
it works, but I think creating the file in memory is a better
approach, so I changed the 2nd lineI(using php 5.2.0) to
$filename = 'php://temp/xxx.zip';
then the php just won't archive the file and the file downloaded is
just a plain text file.

so
question 1, how to create zip Archive file in memory on the fly and
download it (I don't have to save it on disk)?
question 2, if there is no way to create in memory, is it safe to just
unlink() the file?

thanks in advance.

--- End Message ---
--- Begin Message ---
On 9 February 2010 15:42, Ryan Sun <ryansu...@gmail.com> wrote:
> I want to generate credential zip file for user on the fly with
> zipArchive and render it for download, so I created following code
> ---------------------------------------------------------
> $zip = new ZipArchive();
> $filename = '/tmp/xxx.zip';
> if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
>      throw new Exception();
> }
> if($zip)
> {
>     $zip->addFromString('xxx.xx', $fileString);
> }
> $zip->close();
> $fileString = file_get_contents($filename);
> unlink($filename);
>
> $this->getResponse()->setHeader('Content-Type', 'application/zip');
> $this->getResponse()->setHeader('Content-Disposition','attachment;filename=xxx.zip');
> $this->getResponse()->setBody($fileString);
> -----------------------------------------------------
> it works, but I think creating the file in memory is a better
> approach, so I changed the 2nd lineI(using php 5.2.0) to
> $filename = 'php://temp/xxx.zip';
> then the php just won't archive the file and the file downloaded is
> just a plain text file.
>
> so
> question 1, how to create zip Archive file in memory on the fly and
> download it (I don't have to save it on disk)?
> question 2, if there is no way to create in memory, is it safe to just
> unlink() the file?
>
> thanks in advance.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

According to http://docs.php.net/manual/en/wrappers.php.php, it looks
like you should be using ...

$filename = 'php://temp';

That's it.

The actual file name is not your job.



-- 
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

--- End Message ---
--- Begin Message ---
thanks, Richard, maybe you are right, the actual file name is not my job
I changed it to 'php://temp' but its still the same, nothing has been changed...

On Tue, Feb 9, 2010 at 11:13 AM, Richard Quadling
<rquadl...@googlemail.com> wrote:
> On 9 February 2010 15:42, Ryan Sun <ryansu...@gmail.com> wrote:
>> I want to generate credential zip file for user on the fly with
>> zipArchive and render it for download, so I created following code
>> ---------------------------------------------------------
>> $zip = new ZipArchive();
>> $filename = '/tmp/xxx.zip';
>> if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
>>      throw new Exception();
>> }
>> if($zip)
>> {
>>     $zip->addFromString('xxx.xx', $fileString);
>> }
>> $zip->close();
>> $fileString = file_get_contents($filename);
>> unlink($filename);
>>
>> $this->getResponse()->setHeader('Content-Type', 'application/zip');
>> $this->getResponse()->setHeader('Content-Disposition','attachment;filename=xxx.zip');
>> $this->getResponse()->setBody($fileString);
>> -----------------------------------------------------
>> it works, but I think creating the file in memory is a better
>> approach, so I changed the 2nd lineI(using php 5.2.0) to
>> $filename = 'php://temp/xxx.zip';
>> then the php just won't archive the file and the file downloaded is
>> just a plain text file.
>>
>> so
>> question 1, how to create zip Archive file in memory on the fly and
>> download it (I don't have to save it on disk)?
>> question 2, if there is no way to create in memory, is it safe to just
>> unlink() the file?
>>
>> thanks in advance.
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> According to http://docs.php.net/manual/en/wrappers.php.php, it looks
> like you should be using ...
>
> $filename = 'php://temp';
>
> That's it.
>
> The actual file name is not your job.
>
>
>
> --
> -----
> Richard Quadling
> "Standing on the shoulders of some very clever giants!"
> EE : http://www.experts-exchange.com/M_248814.html
> EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> ZOPA : http://uk.zopa.com/member/RQuadling
>

--- End Message ---
--- Begin Message ---
Hello,
 
I am working with the SOAP package of PHP and I am trying make a connection
from a hosted website to a server in our office. 
 
I can get to the server perfectly fine from within our office, but I cannot
connect from the eternal site.
 
I have checked and I am certain that the firewall for the server is open.
When I attempt to use the login page that I have created for the website I am
getting the following error message:
 
Connect Error to XX.XX.XX.XXX:8080
 
Where XX.XX.XX.XXX mask the actual ip address of the server. I have tried to
interogate all the values that soap_fault documents that it can return and
the only information I have been able to find beside the above message, which
is the $errorstring, is that my $faultcode = "HTTP".
 
The information that I am getting is very cryptic. if I include our ip
address when I search I get no results. If I put in connect error :8080 I get
millions of meaningless results.
 
Can someone please help to figure out how to get more meaningful information
from soap_fault for this problem so that I can figure out how to fix it.
 
Thank you
 
Eric H. Lommatsch
Programmer
360 Business 
2087 South Grant Street
Denver, CO 80210
Tel 303-777-8939 Ext 23
Fax 888-282-9927
 
er...@360b.com
 

--- End Message ---

Reply via email to