php-general Digest 11 Sep 2012 17:49:06 -0000 Issue 7959

Topics (messages 319032 through 319038):

Re: another Array question
        319032 by: Jim Lucas
        319033 by: admin

Blocking gethostbyname and Net_DNS2 behaviour
        319034 by: a m
        319035 by: a m

redirect a shell command to stdout in real time
        319036 by: zonyi besk
        319037 by: shiplu

fets() escaping some characters
        319038 by: sunil meena

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 ---
On 9/10/2012 9:41 PM, admin wrote:
Hello everyone,

        I have a very long array. I want to pull all the data from the array
from a certain position to a certain position.
$myarray = array('0'=>'me', '1'=>'you','2'=>'her','3'=>'him','4'=>'them',
'5'=>'us');
Yes I know the array above it small it's an example, mine has over 150
positions.

$foundyou = array_search('you', $myarray);
$foundthem = array_search('them', $myarray);

Now I want to take all the array positions from $foundyou to $foundthem and
put their values into a variable;
For the life of me I can't remember how I did it.

I DO NOT want to foreach over the array positions that would be
counterproductive.


Well, depends on exactly what you mean by "and put their values into a variable". Do you mean concatenate all the values into one single "flat" variable. Or do you mean to make a subset array of the values between your two points you found?


First, check out array_slice.
Second, look at join


<?php

$myarray = array(
  '0'=>'me',
  '1'=>'you',
  '2'=>'her',
  '3'=>'him',
  '4'=>'them',
  '5'=>'us',
);

$s_pos = array_search('you', $myarray);
$f_pos = array_search('them', $myarray);

# Calculate the length, it is needed by array_slice()
$length = ($f_pos - $s_pos);

$subset_array = array_slice($myarray, $s_pos, $length);

print_r($subset_array);

$all_values = join(', ', $subset_array);

echo $all_values;

?>

Obviously, you need to add in some error checking. But that should get you started.

--
Jim

--- End Message ---
--- Begin Message ---
Length was my problem the whole time.
Thank you very much.

Resolved 


-----Original Message-----
From: Jim Lucas [mailto:li...@cmsws.com] 
Sent: Tuesday, September 11, 2012 1:02 AM
To: admin
Cc: php-gene...@lists.php.net
Subject: Re: [PHP] another Array question

On 9/10/2012 9:41 PM, admin wrote:
> Hello everyone,
>
>       I have a very long array. I want to pull all the data from the array

> from a certain position to a certain position.
> $myarray = array('0'=>'me', 
> '1'=>'you','2'=>'her','3'=>'him','4'=>'them',
> '5'=>'us');
> Yes I know the array above it small it's an example, mine has over 150 
> positions.
>
> $foundyou = array_search('you', $myarray); $foundthem = 
> array_search('them', $myarray);
>
> Now I want to take all the array positions from $foundyou to 
> $foundthem and put their values into a variable; For the life of me I 
> can't remember how I did it.
>
> I DO NOT want to foreach over the array positions that would be 
> counterproductive.
>

Well, depends on exactly what you mean by "and put their values into a
variable".  Do you mean concatenate all the values into one single "flat"
variable.  Or do you mean to make a subset array of the values between your
two points you found?


First, check out array_slice.
Second, look at join


<?php

$myarray = array(
   '0'=>'me',
   '1'=>'you',
   '2'=>'her',
   '3'=>'him',
   '4'=>'them',
   '5'=>'us',
);

$s_pos = array_search('you', $myarray);
$f_pos = array_search('them', $myarray);

# Calculate the length, it is needed by array_slice() $length = ($f_pos -
$s_pos);

$subset_array = array_slice($myarray, $s_pos, $length);

print_r($subset_array);

$all_values = join(', ', $subset_array);

echo $all_values;

?>

Obviously, you need to add in some error checking.  But that should get you
started.

--
Jim


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

I was using gethostbyname up until recently but switched to Net_DNS2
due to lack of support for a timeout. Now I discovered some "worrying"
behaviour and hope someone here get shed some light onto it.

I am running PHP inside an Apache 2 installation as module and noticed
that once I call gethostbyname it appears to block all other
concurrent independent requests to PHP pages until the call returned.
I do seem to remember that there were some reentrant issues with the
native gethostbyname function but I wouldnt assume there is some kind
of global lock on it blocking the entire runtime.

What is even more worrying is that Net_DNS2 appears to show the same
behaviour, even though from my understanding it is supposed to work
completely independent with its own streams/sockets.

Of course this behaviour only shows with a domain with non-responding
name servers, hence I used vuav.com. You should be able to reproduce
it easily with

<?php

        echo gethostbyname('vuav.com');

        // OR ......

        require('Net/DNS2.php');

        $dr=new Net_DNS2_Resolver(['nameservers'=>['8.8.8.8']]);
        $ans=$dr->query('vuav.com');
        echo $ans->answer[0]->address;

?>

Could it have to do something with a configuration setting or might I
be onto something?

Thanks a lot!

cheers,
Alexander

--- End Message ---
--- Begin Message ---
My apologies, it looks like it was a false alarm and the blocking
actually comes from PHP's session manager.

Sorry,
Alexander

On 11 September 2012 14:22, a m <ner...@gmail.com> wrote:
> Hi,
>
> I was using gethostbyname up until recently but switched to Net_DNS2
> due to lack of support for a timeout. Now I discovered some "worrying"
> behaviour and hope someone here get shed some light onto it.
>
> I am running PHP inside an Apache 2 installation as module and noticed
> that once I call gethostbyname it appears to block all other
> concurrent independent requests to PHP pages until the call returned.
> I do seem to remember that there were some reentrant issues with the
> native gethostbyname function but I wouldnt assume there is some kind
> of global lock on it blocking the entire runtime.
>
> What is even more worrying is that Net_DNS2 appears to show the same
> behaviour, even though from my understanding it is supposed to work
> completely independent with its own streams/sockets.
>
> Of course this behaviour only shows with a domain with non-responding
> name servers, hence I used vuav.com. You should be able to reproduce
> it easily with
>
> <?php
>
>         echo gethostbyname('vuav.com');
>
>         // OR ......
>
>         require('Net/DNS2.php');
>
>         $dr=new Net_DNS2_Resolver(['nameservers'=>['8.8.8.8']]);
>         $ans=$dr->query('vuav.com');
>         echo $ans->answer[0]->address;
>
> ?>
>
> Could it have to do something with a configuration setting or might I
> be onto something?
>
> Thanks a lot!
>
> cheers,
> Alexander

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

I want to redirect the stdout of an executing shell command to stdout of
php called by browser
The command some stream like command like
ffmpeg -i rtmp://192.....     -
rtmpdump -v  -r rtmp://192  -a app -y stream -o -
so its live video, and the execution not stops,  till the user navigate out
with browser.

What I want loading this php from web based,  to print the live video
content to the stdout of php,
So the call result of  php is video and starts almost with
header("Content-Type: video/x-flv");

Hope there's solution in php
Thanks
Zocs

--- End Message ---
--- Begin Message ---
You can use pipe to run the command and capture the stdout.
Then dump it with proper header to browser.

Note, If the external command (specially video encoding) takes long time
you should probably use cron for this and maintain a queue. I recommend you
apply some sorts of caching also.

-- 
Shiplu.Mokadd.im
ImgSign.com | A dynamic signature machine
Innovation distinguishes between follower and leader

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

Very new to the list.

So I am trying to echo a string to the browser as follows -

$str = "0x100092000 -        0x1000b7fff +com.apple.com (2.0 - 56)
<BB91F4F8-3B1B-93C6-0D1A-E431E96F1BA3> /Library/PrivateFrameworks";

echo $str;

However the text between "<" and ">" i.e
"BB91F4F8-3B1B-93C6-0D1A-E431E96F1BA3" doesn't get echoed instead all I get
is "0x100092000 -        0x1000b7fff +com.apple.com (2.0 - 56)
/Library/PrivateFrameworks";

Anyone knows why this is happening?

This happened while I was getting a line using fgets and hence I tried
storing that string into a variable and outputting but it still doesn't
show the characters between the "<>".

Any help is highly appreciated.

Thanks

-- 
Best Regards,
Sunil Meena

--- End Message ---

Reply via email to