php-general Digest 14 Oct 2009 03:08:03 -0000 Issue 6389

Topics (messages 298878 through 298886):

Re: Insult my code!
        298878 by: David Otton

Bug in php-cgi.exe
        298879 by: loki

Re: How to bypass (pipe) curl_exec return value directly to a file?
        298880 by: Andrea Giammarchi
        298881 by: Andrea Giammarchi
        298882 by: Lars Torben Wilson
        298883 by: Andrea Giammarchi
        298884 by: Lars Torben Wilson
        298885 by: Andrea Giammarchi

Signing (hand-written signature) pdf document
        298886 by: nashrul

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 ---
2009/10/13 Eric Bauman <baum...@livejournal.dk>:

> *sigh* sometimes I really wish PHP allowed one to be a bit more heavy-handed
> with types (optional real type hinting would be nice).

There's a scalar type-hinting patch floating around somewhere, but
then your code would only work on machines with that patch.

> I guess I only ever worried about string (from DB) and int (internal call)
> as in my specific use I would never be passing a float.
> You make an excellent point however; I suppose in the interests of
> completeness, forward compatibility etc. I should take into account more
> possibilities. Perhaps I should just throw an exception in deposit() etc. if
> the argument isn't int and worry about converting elsewhere.

I can see two choices - either throw an exception in checkInt() if
it's passed anything except an int or a string (which is fine -
because you've made the assumption explicit) or change the checkInt()
so it deals with ints-masquerading-as-floats. Try:

function checkInt($x) {
    return((string)((int)$x) == $x);
}

> Also thanks for the sample TestCase code! I've never really thought about
> unit testing in PHP, despite doing so in Java etc. Reading about PHPUnit
> brought me on to phpUnderControl - interesting stuff!

Yup. Pretty graphs. That's not the best unit test example to work
from, BTW - the manual will give you better advice than I.

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

i thing i found a bug in PHP-cgi.exe

I use Php-cgi as fastCgi

php-cgi.exe -b host:port

i set in environement variables this :

PHP_FCGI_CHILDREN=8
PHP_FCGI_MAX_REQUESTS=1000

in the task manager i see only one  Php-cgi.exe
process (when normaly i must see 9 process no?)
and after i send more than 1000 request the
php-cgi.exe process died ! and i must manually
restart it!


Thanks you by advance for you help

--
stephane

Http://www.arkadia.com/fra/
Http://www.arkadia.com/usa/
Http://www.arkadia.com/rus/

--- End Message ---
--- Begin Message ---
I guess this should work

set_time_limit(0);
$ch = curl_init($siteURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_FILE, 'stream.bin');
curl_exec($ch);

Regards

> From: magda.hasib...@yahoo.co.uk
> To: php-gene...@lists.php.net
> Date: Tue, 13 Oct 2009 11:01:04 +0700
> Subject: [PHP] How to bypass (pipe) curl_exec return value directly to a file?
> 
> Newbie question.
> I need to download a very large amount of xml data from a site using CURL.
> 
> How to bypass (pipe) curl_exec return value directly to a file, without
> using memory allocation?
> 
> set_time_limit(0);
> $ch = curl_init($siteURL);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
> $mixed = curl_exec($ch);
> 
> How to set/pipe $mixed as a (disk) file, so that data returned by curl_exec
> is directly saved to the disk-file, and not involving memory allocation?
> 
> Thank you.
> 
> -PHP 5
> -Windows XP
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
                                          
_________________________________________________________________
Windows Live: Make it easier for your friends to see what you’re up to on 
Facebook.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_2:092009

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

>   $ch = curl_init($url);
>   $fp = fopen('/tmp/curl.out', 'w');
>   curl_setopt($ch, CURLOPT_FILE, $fp);
>   curl_exec($ch);
> 
> Error checking etc. is of course left up to you. :)

oops, I sent directly the file name. Let me reformulate the code then:


set_time_limit(0);
$fp = fopen('stream.bin', 'wb');
$ch = curl_init($siteURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
fclose($fp);

Apologize I did not test it before.

Regards

                                          
_________________________________________________________________
Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail 
you.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010

--- End Message ---
--- Begin Message ---
2009/10/13 Andrea Giammarchi <an_...@hotmail.com>:
>
>> $ch = curl_init($url);
>> $fp = fopen('/tmp/curl.out', 'w');
>> curl_setopt($ch, CURLOPT_FILE, $fp);
>> curl_exec($ch);
>>
>> Error checking etc. is of course left up to you. :)
>
> oops, I sent directly the file name. Let me reformulate the code then:
>
>
> set_time_limit(0);
> $fp = fopen('stream.bin', 'wb');
> $ch = curl_init($siteURL);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
> curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);

If you're re-using a curl handle then it may be a good idea to set
these explicitly. However, these are also the default values so it's
not really necessary to set them for a new handle. You're right that
it's a good idea to include the 'b' in the fopen() mode.

> curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);

I wouldn't recommend setting this to 0 unless you're very sure that
the connection will succeed; otherwise, your script will hang
indefinitely waiting for the connection to be made.


Regards,

Torben

> curl_setopt($ch, CURLOPT_FILE, $fp);
> curl_exec($ch);
> fclose($fp);
>
> Apologize I did not test it before.
>
> Regards
>
>
> ________________________________
> Windows Live: Friends get your Flickr, Yelp, and Digg updates when they
> e-mail you.

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

> > curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
> 
> I wouldn't recommend setting this to 0 unless you're very sure that
> the connection will succeed; otherwise, your script will hang
> indefinitely waiting for the connection to be made.

agreed, it's just he set timeout to zero so I guess he meant the curl 
connection as well otherwise it does not make sense to set the timeout to 0 if 
curl has 10 seconds timeout :-)

Regards
                                          
_________________________________________________________________
Windows Live Hotmail: Your friends can get your Facebook updates, right from 
Hotmail®.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_4:092009

--- End Message ---
--- Begin Message ---
2009/10/13 Andrea Giammarchi <an_...@hotmail.com>:
>
>> > curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
>>
>> I wouldn't recommend setting this to 0 unless you're very sure that
>> the connection will succeed; otherwise, your script will hang
>> indefinitely waiting for the connection to be made.
>
> agreed, it's just he set timeout to zero so I guess he meant the curl
> connection as well otherwise it does not make sense to set the timeout to 0
> if curl has 10 seconds timeout :-)
>
> Regards

If he wants to download a very large file then it would make sense to
set_time_limit(0) but leave the curl connect timeout enabled; he
wouldn't want the PHP script timing out partway through a large
download. :) The curl timeout isn't for the transfer; just for making
the connection.


Regards,

Torben

--- End Message ---
--- Begin Message ---
uhm, right, I should have better explain that option ... still, if timelimit is 
0, I guess connection timeout matters, maybe I am wrong.

Thanks.

Regards

> Date: Tue, 13 Oct 2009 11:31:00 -0700
> Subject: Re: [PHP] How to bypass (pipe) curl_exec return value directly to a  
> file?
> From: larstor...@gmail.com
> To: an_...@hotmail.com
> CC: magda.hasib...@yahoo.co.uk; php-gene...@lists.php.net
> 
> 2009/10/13 Andrea Giammarchi <an_...@hotmail.com>:
> >
> >> > curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
> >>
> >> I wouldn't recommend setting this to 0 unless you're very sure that
> >> the connection will succeed; otherwise, your script will hang
> >> indefinitely waiting for the connection to be made.
> >
> > agreed, it's just he set timeout to zero so I guess he meant the curl
> > connection as well otherwise it does not make sense to set the timeout to 0
> > if curl has 10 seconds timeout :-)
> >
> > Regards
> 
> If he wants to download a very large file then it would make sense to
> set_time_limit(0) but leave the curl connect timeout enabled; he
> wouldn't want the PHP script timing out partway through a large
> download. :) The curl timeout isn't for the transfer; just for making
> the connection.
> 
> 
> Regards,
> 
> Torben
                                          
_________________________________________________________________
Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail 
you.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010

--- End Message ---
--- Begin Message ---
Hi...
I'm thinking about a document management system that can put user signature
on the created digital document. Here's the app-flow I can imagine ...
My php application creates a pdf document.
The pdf document is displayed to user.
Using the digital pen, the user will put his/her signature on this document.
or Using the touch screen, the user will put his/her signature.
The pdf document with the user signature is saved to the db.
Has anyone done this before ??
Thanks
-- 
View this message in context: 
http://www.nabble.com/Signing-%28hand-written-signature%29-pdf-document-tp25884660p25884660.html
Sent from the PHP - General mailing list archive at Nabble.com.


--- End Message ---

Reply via email to