cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: status not separated from content

From: Ralph Mitchell <rmitchell_at_eds.com>
Date: Tue, 10 Jun 2003 00:31:26 -0500

The reason the status info runs together with the file data is that you've told it to... The status output is
coming out on the stderr channel whenever it's ready, and your "2>&1" makes it blend with the file data that
you're having sent to the stdout channel.

Looks like shell_exec is a PHP function, right? If so, have you looked into:

1) using curl built into PHP, instead of exec'ing a shell. Obviously this only works if the PHP you have
available has curl built-in... :)

2) PHP function proc_open. This allows you to open multiple pipes to the shell. In other words, you'd create a
couple of pipes for stdout and stderr, then call proc_open. You'd then read the file data from the stdout pipe
and any status stuff from the stderr pipe. There's a very good example in the PHP manual page:

    http://www.php.net/manual/en/function.proc-open.php

No, I haven't used it myself, and it's not available in PHP below v4.3.0.

Ralph Mitchell

noise factor wrote:

> here's a glimpse of some trouble i'm having that shouldn't be
> this bad. thanks for your consideration.
> Andy
>
> in my script i'm using
> $contents = shell_exec("curl -r 0-4096 -o - $url 2>&1");
>
> where it is vital to have both the file and the alleged filesize.
> so i must use the the status report or the verbose output, both of
> which give this filesize total. the problems are the following:
> A) this value should be a variable in the -w option format
> B) when i capture the output with -o - the data runs together with
> the status info in a way that makes it particularly difficult to
> separate the two, for example:
>
> 4 29233 4 1368 0 0 331 0 0:01:28 0:00:04 0:01:24 331Falalalalalalalalalala file data...
>
> for the sake of speed, i really shouldn't have to send this data to
> the hard drive to separate curl's diagnostic data from the file data.
> an endline character would help.
>
> C) if i use -- gulp -- -s and -v to get the 29233 filesize total, i
> then have to start guessing about what is in the file in order to
> strip away the verbose curl comments, which don't even all begin with the same characters

-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
Received on 2003-06-10