php-general Digest 8 Apr 2010 11:42:47 -0000 Issue 6681
Topics (messages 303875 through 303891):
Re: mysql query returning slowly
303875 by: David Murphy
Re: Howto send command over ssh using sockets
303876 by: Thomas Anderson
Greate day for you,
303877 by: Chris G
303878 by: Daniel Brown
303879 by: Nilesh Govindarajan
303880 by: Bruno Fajardo
303881 by: Kevin Kinsey
303882 by: HallMarc Websites
Sort two coupled arrays
303883 by: tedd
303884 by: Piero Steinger
303885 by: Mattias Thorslund
303886 by: Paul M Foster
303887 by: Andrew Ballard
303888 by: Hans Ã
hlin
Re: Sort two coupled arrays {my solution]
303889 by: tedd
303890 by: Ryan Sun
Beginner's question: How to run a PHP web application locally?
303891 by: Bastien Helders
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 ---
Nathan,
The profiling I included proved that was not the case.
Mysql run the query and return the single column single row result in under
1 second but PHP's mysql->query waited much longer than that to return. If
it was a big result set I could see some slow down in parsing the results
into memory but this wasn't the case. Updates/Deletes have similar random
timing issues , and using mysql profiling, I can see its not transit or
lock or clean up time from mysql <-> php , it is purely inside the php
mysql functions the slow down seems to be occurs , but I can dive into
those as they are compiled modules not userland functions.
-----Original Message-----
-----Original Message-----
From: Nathan Rixham [mailto:nrix...@gmail.com]
Sent: Tuesday, April 06, 2010 6:35 PM
To: David Murphy
Cc: php-gene...@lists.php.net
Subject: Re: mysql query returning slowly
David Murphy wrote:
>
> This is from our application
> I enabled profile in mysql to determine why an update took 20seconds. As
> you can see MySQL reported no where near that amount of duration took
> place.
> Is there any way I can dig into php and determine why mysql client libs
are
> so slow (this is not using mysqlnd but mysql-client-libs on CentOS using
> 5.3.2)
>
>
> 04/06/2010 14:54:54 20.6899s
maybe it was waiting to acquire a lock
--- End Message ---
--- Begin Message ---
phpseclib does SSH without PECL extension and only with fsockopen:
http://phpseclib.sourceforge.net/
On Sun Apr 4 21:09:54 2010, Hans_Åhlin wrote:
> Instead of ssh, you could use telnet to connect to the Cisco router
> (which incidentally runs on port 23, but is likely to be disabled on
> the cisco router, unless you have a pre-SSH capable IOS running on it
> (like my old cisco crap :( ) ), because i strongly doubt you have
> written or are willing to write your own encryption libraries for this
> project, you might also want to read IETF RFC 854
> [http://tools.ietf.org/html/rfc854] about the telnet protocol, as you
> are writing your own client, and not using a pre-made one, judging
> from your script.
> Or if you do not like the idea of sending clear-text passwords to the
> router, you might want to learn about proc_open() (or popen()) and use
> the native ssh utility that most likely is present on the server,
> taking great care to READ THE MANUAL for the ssh command, because you
> most likely do _not_ want it to spit out ANSI-escapes to you script.
>
> Kind regards from
> Johan Lidström
> Örnsköldsvik, Sweden
> irc://irc.freenode.net/Dr_Kao
> frozendude+php...@gmail.com
>
> P.S. currently borrowing a friends account.
>
> 2010/4/5 Radek Krejča <radek.kre...@starnet.cz>:
>> Hello,
>>
>> I am trying send command to remote host over ssh with sockets. But I need to
>> set up username/password. I am trying to modify this script (from
>> www.php.net - function fsockopen), but I dont know, where set
>> username/password because I got this message:
>> Bad protocol version identification 'password' from ip
>>
>> Library ssh2 is not currentu userfull for me, because I am not admin of
>> server.
>>
>> Thank you
>> Radek
>>
>>
>> <?php
>> /************************************************************
>> * Author: Richard Lajaunie
>> * Mail : richard.lajau...@cote-azur.cci.fr
>> *
>> * subject : this script retreive all mac-addresses on all ports
>> * of a Cisco 3548 Switch by a telnet connection
>> *
>> * base on the script by: xbensemhoun at t-systems dot fr on the same page
>> **************************************************************/
>>
>> if ( array_key_exists(1, $argv) ){
>> $cfgServer = $argv[1];
>> }else{
>> echo "ex: 'php test.php 10.0.0.0' \n";
>> exit;
>> }
>>
>> $cfgPort = 23; //port, 22 if SSH
>> $cfgTimeOut = 10;
>>
>> $usenet = fsockopen($cfgServer, $cfgPort, $errno, $errstr), $cfgTimeOut);
>>
>> if(!$usenet){
>> echo "Connexion failed\n";
>> exit();
>> }else{
>> echo "Connected\n";
>> fputs ($usenet, "password\r\n");
>> fputs ($usenet, "en\r\n");
>> fputs ($usenet, "password\r\n");
>> fputs ($usenet, "sh mac-address-table\r\n");
>> fputs ($usenet, " "); // this space bar is this for long output
>>
>> // this skip non essential text
>> $j = 0;
>> while ($j<16){
>> fgets($usenet, 128);
>> $j++;
>> }
>> stream_set_timeout($usenet, 2); // set the timeout for the fgets
>> $j = 0;
>> while (!feof($usenet)){
>> $ret = fgets($usenet, 128);
>> $ret = str_replace("\r", '', $ret);
>> $ret = str_replace("\n", "", $ret);
>> if (ereg("FastEthernet", $ret)){
>> echo "$ret \n";
>> }
>> if (ereg('--More--', $ret) ){
>> fputs ($usenet, " "); // for following page
>> }
>> $info = stream_get_meta_data($usenet);
>> if ($info['timed_out']) {
>> $j++;
>> }
>> if ($j >2){
>> fputs ($usenet, "lo");
>> break;
>> }
>> }
>> }
>> echo "End.\r\n";
>> ?>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
--- End Message ---
--- Begin Message ---
http://sites.google.com/site/vfgbyuhoi6/kewe2w
--- End Message ---
--- Begin Message ---
On Wed, Apr 7, 2010 at 12:11, Chris G <thunder...@gmail.com> wrote:
> http://sites.google.com/site/vfgbyuhoi6/kewe2w
Heads-up: It's a SPAM link. You probably already knew that.
(Funny that Jochem was targeted directly for this particular one. ;-P)
--
</Daniel P. Brown>
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Looking for hosting or dedicated servers? Ask me how we can fit your budget!
--- End Message ---
--- Begin Message ---
On 04/07/10 21:41, Chris G wrote:
http://sites.google.com/site/vfgbyuhoi6/kewe2w
Bloody asshole spammer.
Is there no spam filter at lists.php.net ?
--
Nilesh Govindarajan
Site & Server Administrator
www.itech7.com
मेरा भारत महान !
मम भारत: महत्तम भवतु !
--- End Message ---
--- Begin Message ---
2010/4/7 Nilesh Govindarajan <li...@itech7.com>:
> On 04/07/10 21:41, Chris G wrote:
>>
>> http://sites.google.com/site/vfgbyuhoi6/kewe2w
>>
>
> Bloody asshole spammer.
> Is there no spam filter at lists.php.net ?
It was probably a virus or a trojahn, not intentionally sent to the
list by the OP...
>
> --
> Nilesh Govindarajan
> Site & Server Administrator
> www.itech7.com
> मेरा भारत महान !
> मम भारत: महत्तम भवतु !
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Nilesh Govindarajan wrote:
On 04/07/10 21:41, Chris G wrote:
http://sites.google.com/site/vfgbyuhoi6/kewe2w
<snip>
Is there no spam filter at lists.php.net ?
Does your filter catch 101% of all of it? That's
the only one I've seen in a Long Time(tm).
Just asking :-)
Kevin Kinsey
--- End Message ---
--- Begin Message ---
-----Original Message-----
From: Chris G [mailto:thunder...@gmail.com]
Sent: Wednesday, April 07, 2010 12:11 PM
To: denisema...@googlemail.com; derrick.h...@za.delarue.com;
gc...@aceonline.com.au; ja...@shongololocomm.co.za; joc...@iamjochem.com;
bonge...@mweb.co.za; johan.bong...@za.delarue.com;
jonathanbus-...@telkomsa.net; kmfisc...@gmail.com; kell...@trtretail.co.za;
kerry.gri...@gmail.com; kirst...@switchdesign.com; s.ku...@huxley.co.uk;
lee.mais...@7layer.net; mik.gri...@za.delarue.com; paintball...@hotmail.com;
paintball...@yahoo.com; php-gene...@lists.php.net;
php-general-unsubscr...@lists.php.net; scot...@mkbgroup.co.za
Subject: [PHP] Greate day for you,
http://sites.google.com/site/vfgbyuhoi6/kewe2w
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
It looks like the mighty Gmail has been cracked. This is the second time
today I have seen something like this and both have originated through
actual gmail accounts and CC to people on their mailing lists.
__________ Information from ESET Smart Security, version of virus signature
database 5007 (20100407) __________
The message was checked by ESET Smart Security.
http://www.eset.com
__________ Information from ESET Smart Security, version of virus signature
database 5008 (20100407) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--- End Message ---
--- Begin Message ---
Hi gang:
Here's the problem -- I want to sort and combine two arrays into one
sorted array. Here's a real-world example:
Array 1
(
[1] => 75
[2] => 31
[3] => 31
[4] => 31
[5] => 40
)
Array 2
(
[1] => Personal Email
[2] => Personal Phone
[3] => Web site
[4] => Text Message
[5] => USPS mail
)
After the operation, I want this:
Array
(
[75] => Personal Email
[40] => USPS mail
[31] => Personal Phone
[31] => Web site
[31] => Text Message
)
Note: This is a descending-sort of Array 1 while being coupled to
index of Array 2. In other words, the order of Array 2 depends upon
the order of Array 1 -- the two arrays are coupled.
I've solved this problem, but my solution is pretty lame. There has
to be a better/slicker way.
Suggestions?
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
Am 07.04.2010 22:09, schrieb tedd:
> Hi gang:
>
> Here's the problem -- I want to sort and combine two arrays into one
> sorted array. Here's a real-world example:
>
> Array 1
> (
> [1] => 75
> [2] => 31
> [3] => 31
> [4] => 31
> [5] => 40
> )
>
> Array 2
> (
> [1] => Personal Email
> [2] => Personal Phone
> [3] => Web site
> [4] => Text Message
> [5] => USPS mail
> )
>
> After the operation, I want this:
>
> Array
> (
> [75] => Personal Email
> [40] => USPS mail
> [31] => Personal Phone
> [31] => Web site
> [31] => Text Message
> )
>
> Note: This is a descending-sort of Array 1 while being coupled to
> index of Array 2. In other words, the order of Array 2 depends upon
> the order of Array 1 -- the two arrays are coupled.
>
> I've solved this problem, but my solution is pretty lame. There has to
> be a better/slicker way.
>
> Suggestions?
>
> Cheers,
>
> tedd
array_combine($key_array, $value_array)
:)
-- Piero
--- End Message ---
--- Begin Message ---
Piero Steinger wrote:
Am 07.04.2010 22:09, schrieb tedd:
Hi gang:
Here's the problem -- I want to sort and combine two arrays into one
sorted array. Here's a real-world example:
Array 1
(
[1] => 75
[2] => 31
[3] => 31
[4] => 31
[5] => 40
)
Array 2
(
[1] => Personal Email
[2] => Personal Phone
[3] => Web site
[4] => Text Message
[5] => USPS mail
)
After the operation, I want this:
Array
(
[75] => Personal Email
[40] => USPS mail
[31] => Personal Phone
[31] => Web site
[31] => Text Message
)
Note: This is a descending-sort of Array 1 while being coupled to
index of Array 2. In other words, the order of Array 2 depends upon
the order of Array 1 -- the two arrays are coupled.
I've solved this problem, but my solution is pretty lame. There has to
be a better/slicker way.
Suggestions?
Cheers,
tedd
array_combine($key_array, $value_array)
:)
-- Piero
And then:
krsort($combined_array);
Cheers,
Mattias
--- End Message ---
--- Begin Message ---
On Wed, Apr 07, 2010 at 04:09:47PM -0400, tedd wrote:
> Hi gang:
>
> Here's the problem -- I want to sort and combine two arrays into one
> sorted array. Here's a real-world example:
>
> Array 1
> (
> [1] => 75
> [2] => 31
> [3] => 31
> [4] => 31
> [5] => 40
> )
>
> Array 2
> (
> [1] => Personal Email
> [2] => Personal Phone
> [3] => Web site
> [4] => Text Message
> [5] => USPS mail
> )
>
> After the operation, I want this:
>
> Array
> (
> [75] => Personal Email
> [40] => USPS mail
> [31] => Personal Phone
> [31] => Web site
> [31] => Text Message
> )
>
> Note: This is a descending-sort of Array 1 while being coupled to
> index of Array 2. In other words, the order of Array 2 depends upon
> the order of Array 1 -- the two arrays are coupled.
>
> I've solved this problem, but my solution is pretty lame. There has
> to be a better/slicker way.
Just so I understand the way arrays work in PHP (gee, I *thought* I
did!), as you add the final three elements in the final array, won't
they overwrite each other? I was under the impression that a
*numerically* indexed array has a constraint that the numeric indexes be
unique, if not contiguous. Am I wrong? If so, please provide a
reference. Or are those "numbers" really strings?
Paul
--
Paul M. Foster
--- End Message ---
--- Begin Message ---
On Wed, Apr 7, 2010 at 5:02 PM, Paul M Foster <pa...@quillandmouse.com> wrote:
> On Wed, Apr 07, 2010 at 04:09:47PM -0400, tedd wrote:
>
>> Hi gang:
>>
>> Here's the problem -- I want to sort and combine two arrays into one
>> sorted array. Here's a real-world example:
>>
>> Array 1
>> (
>> [1] => 75
>> [2] => 31
>> [3] => 31
>> [4] => 31
>> [5] => 40
>> )
>>
>> Array 2
>> (
>> [1] => Personal Email
>> [2] => Personal Phone
>> [3] => Web site
>> [4] => Text Message
>> [5] => USPS mail
>> )
>>
>> After the operation, I want this:
>>
>> Array
>> (
>> [75] => Personal Email
>> [40] => USPS mail
>> [31] => Personal Phone
>> [31] => Web site
>> [31] => Text Message
>> )
[snip]
> Just so I understand the way arrays work in PHP (gee, I *thought* I
> did!), as you add the final three elements in the final array, won't
> they overwrite each other? I was under the impression that a
> *numerically* indexed array has a constraint that the numeric indexes be
> unique, if not contiguous. Am I wrong? If so, please provide a
> reference. Or are those "numbers" really strings?
>
> Paul
>
> --
> Paul M. Foster
Array indexes have to be unique regardless of whether they are numeric
or strings.
<?php
$a = array
(
1 => '75',
2 => '31',
3 => '31',
4 => '31',
5 => '40',
);
$b = array
(
1 => 'Personal Email',
2 => 'Personal Phone',
3 => 'Web site',
4 => 'Text Message',
5 => 'USPS mail',
);
$x = array_combine($a, $b);
var_export($x);
/*
array (
75 => 'Personal Email',
31 => 'Text Message',
40 => 'USPS mail',
)
*/
echo "\n";
krsort($x);
var_export($x);
/*
array (
75 => 'Personal Email',
40 => 'USPS mail',
31 => 'Text Message',
)
*/
?>
Andrew
--- End Message ---
--- Begin Message ---
Try this insted
array(
[0]=>array( [0]=>75, [1] => Personal Email)
[1]=>array( [0]=>31, [1] => Personal Phone)
[2]=>array( [0]=>31, [1] => Web site)
[3]=>array( [0]=>31, [1] => Text Message)
[4]=>array( [0]=>40, [1] => USPS mail)
MvH / Hans Åhlin
Tel: +46761488019
http://www.kronan-net.com/
irc://irc.freenode.net:6667 - TheCoin
2010/4/7 tedd <t...@sperling.com>:
> Hi gang:
>
> Here's the problem -- I want to sort and combine two arrays into one sorted
> array. Here's a real-world example:
>
> Array 1
> (
> [1] => 75
> [2] => 31
> [3] => 31
> [4] => 31
> [5] => 40
> )
>
> Array 2
> (
> [1] => Personal Email
> [2] => Personal Phone
> [3] => Web site
> [4] => Text Message
> [5] => USPS mail
> )
>
> After the operation, I want this:
>
> Array
> (
> [75] => Personal Email
> [40] => USPS mail
> [31] => Personal Phone
> [31] => Web site
> [31] => Text Message
> )
>
> Note: This is a descending-sort of Array 1 while being coupled to index of
> Array 2. In other words, the order of Array 2 depends upon the order of
> Array 1 -- the two arrays are coupled.
>
> I've solved this problem, but my solution is pretty lame. There has to be a
> better/slicker way.
>
> Suggestions?
>
> Cheers,
>
> tedd
> --
> -------
> http://sperling.com http://ancientstones.com http://earthstones.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
At 5:35 PM -0400 4/7/10, Andrew Ballard wrote:
On Wed, Apr 7, 2010 at 5:02 PM, Paul M Foster <pa...@quillandmouse.com> wrote:
Array indexes have to be unique regardless of whether they are numeric
or strings.
Ahhh, so you start to see the problem, eh?
Let's look at the problem again (a vote collection problem):
Array 1
(
[1] => 75
[2] => 31
[3] => 31
[4] => 31
[5] => 40
)
Array 1 is an array that contains the count of votes ($votes[] ) for
the index. IOW, index 1 received 75 votes.
Array 2
(
[1] => Personal Email
[2] => Personal Phone
[3] => Web site
[4] => Text Message
[5] => USPS mail
)
Array 2 is an array that contains the names for the items ($items[] )
voted upon. As such, index 1 (Personal Email) received 75 votes.
Now, I have this data in two different arrays and I wanted to combine
the data into one array and then preform a descend sort.
This is the way I solved it:
$final = array();
for($i =1; $i <=5; $i++)
{
$final[$i][] = $votes[$i];
$final[$i][] = $items[$i];
}
echo("<pre>");
echo('<br>');
print_r($final);
echo('<br>');
array_multisort($final, SORT_DESC);
echo('<br>');
print_r($final);
echo('<br>');
echo("</pre>");
I was hoping that someone might present something clever.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
rsort(array_combine(array2, array1));
you should expect array(
'Personal Email' => 75,
'USPS mail' => 40,
'Personal Phone' => 31,
'Web site' => 31,
'Text Message' => 31
)
logically, the items are your key but not the count of votes
On Wed, Apr 7, 2010 at 6:29 PM, tedd <tedd.sperl...@gmail.com> wrote:
> At 5:35 PM -0400 4/7/10, Andrew Ballard wrote:
>>
>> On Wed, Apr 7, 2010 at 5:02 PM, Paul M Foster <pa...@quillandmouse.com>
>> wrote:
>> Array indexes have to be unique regardless of whether they are numeric
>> or strings.
>
> Ahhh, so you start to see the problem, eh?
>
> Let's look at the problem again (a vote collection problem):
>
> Array 1
> (
> [1] => 75
> [2] => 31
> [3] => 31
> [4] => 31
> [5] => 40
> )
>
> Array 1 is an array that contains the count of votes ($votes[] ) for the
> index. IOW, index 1 received 75 votes.
>
> Array 2
> (
> [1] => Personal Email
> [2] => Personal Phone
> [3] => Web site
> [4] => Text Message
> [5] => USPS mail
> )
>
> Array 2 is an array that contains the names for the items ($items[] ) voted
> upon. As such, index 1 (Personal Email) received 75 votes.
>
> Now, I have this data in two different arrays and I wanted to combine the
> data into one array and then preform a descend sort.
>
> This is the way I solved it:
>
> $final = array();
>
> for($i =1; $i <=5; $i++)
> {
> $final[$i][] = $votes[$i];
> $final[$i][] = $items[$i];
> }
>
> echo("<pre>");
> echo('<br>');
> print_r($final);
> echo('<br>');
>
> array_multisort($final, SORT_DESC);
>
> echo('<br>');
> print_r($final);
> echo('<br>');
> echo("</pre>");
>
> I was hoping that someone might present something clever.
>
> Cheers,
>
> tedd
>
>
> --
> -------
> http://sperling.com http://ancientstones.com http://earthstones.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Hi List,
The other day, I read an article that mentioned about a tool that would
permit to simulate a web environment for PHP, so that testing could be made
before uploading the page on the server. Unfortunately, I don't seem to find
the article again.
So here am I with this question: What should I need to set my test
environment? I'm working on Windows, but I'm all ears for solution on Linux
systems.
Best Regards,
Bastien
--- End Message ---