php-general Digest 23 Jul 2008 21:45:33 -0000 Issue 5585

Topics (messages 277187 through 277213):

Re: Getting info from SVN commit with php
        277187 by: mike
        277189 by: Raido
        277192 by: Daniel Brown
        277193 by: Daniel Brown

Questions about finding ranges
        277188 by: Aslan
        277190 by: Jim Lucas
        277209 by: VamVan
        277210 by: Micah Gersten

Apache blocking certain requests instead of php
        277191 by: Arno Kuhl
        277195 by: Per Jessen
        277211 by: Jim Lucas

Re: a question...
        277194 by: Daniel Brown
        277196 by: Micah Gersten

Re: Reference or copy?
        277197 by: Robert Cummings
        277207 by: Yeti
        277208 by: Ted Wood

Multi-array - What am I missing?
        277198 by: Chris Ditty
        277201 by: Micah Gersten
        277202 by: Chris Ditty
        277203 by: Jason Norwood-Young
        277204 by: Micah Gersten
        277205 by: Micah Gersten
        277206 by: Chris Ditty

big files download with php - configuration problem
        277199 by: Giulio Mastrosanti
        277213 by: mike

$_ENV or getenv to get bash environmental variables.. change php.ini?? env vars
        277200 by: mindspin311

Re: After INSERT form submit - Data doesn't refresh!
        277212 by: VamVan

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
On 7/23/08, Raido <[EMAIL PROTECTED]> wrote:

> I have an SVN server but I need to add some extra to commit message which
> PHP will get  and use(for example use the parameters from commit message to
> change data on mysql database... (if commit messages first line has
> character *, then run sql query... "update tasks set some_row='OK'
> where...."

There's an SVN PECL module: http://pecl.php.net/package/svn

Also, you can easily run these kind of commands via system() - I've
done that in the past, but now that there's this SVN PECL module I've
been wanting to get aligned that way. Always better in my opinion to
use APIs and not system() calls.

If the svn module doesn't meet your needs you can ask for
enhancements, or just use system() for now.

here's a couple functions I wrote.
$config['svn'] was the path to the svn command (like /usr/bin/svn)

i used the xml output option so i could parse it using simplexml.
also, i pass it a username, password and repository since i support
multiple repositories and each one has a unique username/password set.
it worked like a charm. i am sure you can tailor this code to suit
your needs.

# get the latest revision #
function svn_latest($username, $password, $repository) {
        $xml = simplexml_load_string(shell_exec($GLOBALS['config']['svn']."
info --xml --non-interactive --no-auth-cache --username {$username}
--password{$password} svn://localhost/{$repository}"));
        return intval($xml->entry->commit['revision']);
}

function svn_history($username, $password, $repository, $count = 20,
$start = 0, $latest = 0) {
        # svn's revisions are incremental, so we need to calculate
backwards to find the right offsets
        if($latest == 0) {
                $latest = svn_latest($username, $password, $repository);
        }
        $start = $latest - $start;
        $end = intval($start - $count) + 1;
        if($end < 0) { $end = 0; }
        $xml = simplexml_load_string(shell_exec($GLOBALS['config']['svn']."
log --xml --non-interactive --no-auth-cache --username {$username}
--password {$password} -r {$start}:{$end}
svn://localhost/{$repository}"));
        return $xml;
}

--- End Message ---
--- Begin Message ---
Thank You for that fast reply.

PECL was something that I din't know about. But I'll dig in with Your examples and also PECL and try to find most simple but well-working solution.
Also sorry for Return Receipt, turned that off.


mike wrote:
On 7/23/08, Raido <[EMAIL PROTECTED]> wrote:

I have an SVN server but I need to add some extra to commit message which
PHP will get  and use(for example use the parameters from commit message to
change data on mysql database... (if commit messages first line has
character *, then run sql query... "update tasks set some_row='OK'
where...."

There's an SVN PECL module: http://pecl.php.net/package/svn

Also, you can easily run these kind of commands via system() - I've
done that in the past, but now that there's this SVN PECL module I've
been wanting to get aligned that way. Always better in my opinion to
use APIs and not system() calls.

If the svn module doesn't meet your needs you can ask for
enhancements, or just use system() for now.

here's a couple functions I wrote.
$config['svn'] was the path to the svn command (like /usr/bin/svn)

i used the xml output option so i could parse it using simplexml.
also, i pass it a username, password and repository since i support
multiple repositories and each one has a unique username/password set.
it worked like a charm. i am sure you can tailor this code to suit
your needs.

# get the latest revision #
function svn_latest($username, $password, $repository) {
        $xml = simplexml_load_string(shell_exec($GLOBALS['config']['svn']."
info --xml --non-interactive --no-auth-cache --username {$username}
--password{$password} svn://localhost/{$repository}"));
        return intval($xml->entry->commit['revision']);
}

function svn_history($username, $password, $repository, $count = 20,
$start = 0, $latest = 0) {
        # svn's revisions are incremental, so we need to calculate
backwards to find the right offsets
        if($latest == 0) {
                $latest = svn_latest($username, $password, $repository);
        }
        $start = $latest - $start;
        $end = intval($start - $count) + 1;
        if($end < 0) { $end = 0; }
        $xml = simplexml_load_string(shell_exec($GLOBALS['config']['svn']."
log --xml --non-interactive --no-auth-cache --username {$username}
--password {$password} -r {$start}:{$end}
svn://localhost/{$repository}"));
        return $xml;
}



--- End Message ---
--- Begin Message ---
On Wed, Jul 23, 2008 at 8:22 AM, Raido <[EMAIL PROTECTED]> wrote:
>
> 1) Is it even possible to get commit messages text with php ? Since I can't
> find the file where commit messages are.

    Just a quick answer to this: in your directory of your project
repo, go into the hooks/ subdirectory.  In there, you'll find a
post-commit.tmpl file.  Remove the .tmpl extension and chmod 755
post-commit (if on *NIX).  When a commit is made, post-commit will be
executed by SVN.

    Conversely, if you want the script to execute on a different
trigger, just use a different name for the script, including
pre-commit, pre-lock, post-lock, post-revprop-change, et cetera.

    One of my post-commit scripts looks like this (with names changed
to protect the innocent):

#!/bin/bash
REPOS=$1
REV=$2
AUTHOR=`/usr/bin/svnlook author -r "$REV" "$REPOS"`
CHANGED=`/usr/bin/svnlook changed -r "$REV" "$REPOS"`
DIFF=`/usr/bin/svnlook diff -r "$REV" "$REPOS"`
/usr/bin/php -q /home/repos/sites/example-com/hooks/post-commit.php
"$REPOS" "$REV" "$AUTHOR" "$CHANGED" "$DIFF"


    And then, the PHP script it calls (post-commit.php) from the
shellscript above:

#!/usr/bin/php -q
<?php

$repo = $argv[1];
$rev = $argv[2];
$username = $argv[3];
$changes = $argv[4];
$diff = $argv[5];
$datetime = date("D, j F, Y")." at ".date("H:i:s T");

$to = "[EMAIL PROTECTED]";

$subject = "[SVN] Commit by ".$username;

$body  = "\n";
$body .= "\tChanges have been made to the SVN repository.  The
revision number is now ".$rev.".  Details follow.\n";
$body .= "\n";
$body .= "Committed at ".$datetime."\n";
$body .= "Committed By: ".$username."\n";
$body .= "Repository: ".$repo."\n";
$body .= "Revision # ".$rev."\n";
$body .= "\n\n";
$body .= "List of changes: \n";
$body .= $changes."\n";
$body .= "\n\n";
$body .= "Differences:\n";
$body .= $diff."\n";
$body .= "\n";

$headers  = "From: \"SVN: ".$username."\" <[EMAIL PROTECTED]>\r\n";
$headers .= "X-Mailer: PHP/".phpversion()."\r\n";

mail($to,$subject,$body,$headers);
?>

-- 
</Daniel P. Brown>
Better prices on dedicated servers:
Intel 2.4GHz/60GB/512MB/2TB $49.99/mo.
Intel 3.06GHz/80GB/1GB/2TB $59.99/mo.
Dedicated servers, VPS, and hosting from $2.50/mo.

--- End Message ---
--- Begin Message ---
On Wed, Jul 23, 2008 at 8:22 AM, Raido <[EMAIL PROTECTED]> wrote:
>
> 1) Is it even possible to get commit messages text with php ? Since I can't
> find the file where commit messages are.

    Just a quick answer to this: in your directory of your project
repo, go into the hooks/ subdirectory.  In there, you'll find a
post-commit.tmpl file.  Remove the .tmpl extension and chmod 755
post-commit (if on *NIX).  When a commit is made, post-commit will be
executed by SVN.

    Conversely, if you want the script to execute on a different
trigger, just use a different name for the script, including
pre-commit, pre-lock, post-lock, post-revprop-change, et cetera.

    One of my post-commit scripts looks like this (with names changed
to protect the innocent):

#!/bin/bash
REPOS=$1
REV=$2
AUTHOR=`/usr/bin/svnlook author -r "$REV" "$REPOS"`
CHANGED=`/usr/bin/svnlook changed -r "$REV" "$REPOS"`
DIFF=`/usr/bin/svnlook diff -r "$REV" "$REPOS"`
/usr/bin/php -q /home/repos/sites/example-com/hooks/post-commit.php
"$REPOS" "$REV" "$AUTHOR" "$CHANGED" "$DIFF"


    And then, the PHP script it calls (post-commit.php) from the
shellscript above:

#!/usr/bin/php -q
<?php

$repo = $argv[1];
$rev = $argv[2];
$username = $argv[3];
$changes = $argv[4];
$diff = $argv[5];
$datetime = date("D, j F, Y")." at ".date("H:i:s T");

$to = "[EMAIL PROTECTED]";

$subject = "[SVN] Commit by ".$username;

$body  = "\n";
$body .= "\tChanges have been made to the SVN repository.  The
revision number is now ".$rev.".  Details follow.\n";
$body .= "\n";
$body .= "Committed at ".$datetime."\n";
$body .= "Committed By: ".$username."\n";
$body .= "Repository: ".$repo."\n";
$body .= "Revision # ".$rev."\n";
$body .= "\n\n";
$body .= "List of changes: \n";
$body .= $changes."\n";
$body .= "\n\n";
$body .= "Differences:\n";
$body .= $diff."\n";
$body .= "\n";

$headers  = "From: \"SVN: ".$username."\" <[EMAIL PROTECTED]>\r\n";
$headers .= "X-Mailer: PHP/".phpversion()."\r\n";

mail($to,$subject,$body,$headers);
?>

-- 
</Daniel P. Brown>
Better prices on dedicated servers:
Intel 2.4GHz/60GB/512MB/2TB $49.99/mo.
Intel 3.06GHz/80GB/1GB/2TB $59.99/mo.
Dedicated servers, VPS, and hosting from $2.50/mo.

--- End Message ---
--- Begin Message ---
Hey there,

I have a range of records that represent different faults and different symptoms that I want to pull out of the database, and to find the records that are the closest within each range.

I am currently doing it with a barrage of if statements, but I am sure that this could be done faster and far more elegantly by using SQL

I have a range of conditions eg
Attainable rates:
0-500 KB/sec is very poor
500 - 1000 is marginal
1000- 3000 KB/sec is good

So the database may look like:
Type|Min|Max|Value
Attainable|0|500|" This rate is very poor"

and then SQL could go something like

SELECT * FROM table WHERE Type= "Attainable" AND Min LIKE $var


But that wouldn't work quite right I don't think.

But where it can get a bit more hairy is that I want to have a whole range of variables that are input from an entry table, and then it just finds the the vars that are the closest to what is searching for all the vars. The closest code I have seen doing something similar is where there it is finding if an IP is in a certain range.

Does that make sense? feel free to email me if you need more explanation.

It is kind of like a multi variable search engine, that is finding the root cause of the symptoms that are the very best fit given the multi-variables...

Thanks heaps for any assistance,
Aslan.


--- End Message ---
--- Begin Message ---
Aslan wrote:
Hey there,

I have a range of records that represent different faults and different symptoms that I want to pull out of the database, and to find the records that are the closest within each range.

I am currently doing it with a barrage of if statements, but I am sure that this could be done faster and far more elegantly by using SQL

I have a range of conditions eg
Attainable rates:
0-500 KB/sec is very poor
500 - 1000 is marginal
1000- 3000 KB/sec is good

So the database may look like:
Type|Min|Max|Value
Attainable|0|500|" This rate is very poor"

and then SQL could go something like

SELECT * FROM table WHERE Type= "Attainable" AND Min LIKE $var


You're close, try this

SELECT   *
FROM     table
WHERE    Type = "Attainable"
  AND    Min <= $var
  AND    Max >= $var


as long as your min and max do not overlap from row to row, you should only get one result. Make sure in your data that you have no overlap.

Row 1 =    0 -  499
Row 2 =  500 -  999
Row 3 = 1000 - 1499


But that wouldn't work quite right I don't think.

But where it can get a bit more hairy is that I want to have a whole range of variables that are input from an entry table, and then it just finds the the vars that are the closest to what is searching for all the vars. The closest code I have seen doing something similar is where there it is finding if an IP is in a certain range.

Does that make sense? feel free to email me if you need more explanation.

It is kind of like a multi variable search engine, that is finding the root cause of the symptoms that are the very best fit given the multi-variables...

Thanks heaps for any assistance,
Aslan.




--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare


--- End Message ---
--- Begin Message ---
Hey,

For ranges you can also use "Between" in the mysql queries.

SELECT * FROM table WHERE Type= "Attainable" AND Min LIKE $var can be
written as

Select * from table where between min and max

Just remember that "between" acts a bit wierd with dates or else Jim's
solution would be perfect for you.

Thanks



On Wed, Jul 23, 2008 at 7:58 AM, Jim Lucas <[EMAIL PROTECTED]> wrote:

> Aslan wrote:
>
>> Hey there,
>>
>> I have a range of records that represent different faults and different
>> symptoms that I want to pull out of the database, and to find the records
>> that are the closest within each range.
>>
>> I am currently doing it with a barrage of if statements, but I am sure
>> that this could be done faster and far more elegantly by using SQL
>>
>> I have a range of conditions eg
>> Attainable rates:
>> 0-500 KB/sec is very poor
>> 500 - 1000 is marginal
>> 1000- 3000 KB/sec is good
>>
>> So the database may look like:
>> Type|Min|Max|Value
>> Attainable|0|500|" This rate is very poor"
>>
>> and then SQL could go something like
>>
>> SELECT * FROM table WHERE Type= "Attainable" AND Min LIKE $var
>>
>>
> You're close, try this
>
> SELECT   *
> FROM     table
> WHERE    Type = "Attainable"
>  AND    Min <= $var
>  AND    Max >= $var
>
>
> as long as your min and max do not overlap from row to row, you should only
> get one result.  Make sure in your data that you have no overlap.
>
> Row 1 =    0 -  499
> Row 2 =  500 -  999
> Row 3 = 1000 - 1499
>
>
>> But that wouldn't work quite right I don't think.
>>
>> But where it can get a bit more hairy is that I want to have a whole range
>> of variables that are input from an entry table, and then it just finds the
>> the vars that are the closest to what is searching for all the vars. The
>> closest code I have seen doing something similar is where there it is
>> finding if an IP is in a certain range.
>>
>> Does that make sense? feel free to email me if you need more explanation.
>>
>> It is kind of like a multi variable search engine, that is finding the
>> root cause of the symptoms that are the very best fit given the
>> multi-variables...
>>
>> Thanks heaps for any assistance,
>> Aslan.
>>
>>
>>
>
> --
> Jim Lucas
>
>   "Some men are born to greatness, some achieve greatness,
>       and some have greatness thrust upon them."
>
> Twelfth Night, Act II, Scene V
>    by William Shakespeare
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Here's the info on the "weirdness" of between:
http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_between

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



VamVan wrote:
> Hey,
>
> For ranges you can also use "Between" in the mysql queries.
>
> SELECT * FROM table WHERE Type= "Attainable" AND Min LIKE $var can be
> written as
>
> Select * from table where between min and max
>
> Just remember that "between" acts a bit wierd with dates or else Jim's
> solution would be perfect for you.
>
> Thanks
>
>
>
> On Wed, Jul 23, 2008 at 7:58 AM, Jim Lucas <[EMAIL PROTECTED]> wrote:
>
>   
>> Aslan wrote:
>>
>>     
>>> Hey there,
>>>
>>> I have a range of records that represent different faults and different
>>> symptoms that I want to pull out of the database, and to find the records
>>> that are the closest within each range.
>>>
>>> I am currently doing it with a barrage of if statements, but I am sure
>>> that this could be done faster and far more elegantly by using SQL
>>>
>>> I have a range of conditions eg
>>> Attainable rates:
>>> 0-500 KB/sec is very poor
>>> 500 - 1000 is marginal
>>> 1000- 3000 KB/sec is good
>>>
>>> So the database may look like:
>>> Type|Min|Max|Value
>>> Attainable|0|500|" This rate is very poor"
>>>
>>> and then SQL could go something like
>>>
>>> SELECT * FROM table WHERE Type= "Attainable" AND Min LIKE $var
>>>
>>>
>>>       
>> You're close, try this
>>
>> SELECT   *
>> FROM     table
>> WHERE    Type = "Attainable"
>>  AND    Min <= $var
>>  AND    Max >= $var
>>
>>
>> as long as your min and max do not overlap from row to row, you should only
>> get one result.  Make sure in your data that you have no overlap.
>>
>> Row 1 =    0 -  499
>> Row 2 =  500 -  999
>> Row 3 = 1000 - 1499
>>
>>
>>     
>>> But that wouldn't work quite right I don't think.
>>>
>>> But where it can get a bit more hairy is that I want to have a whole range
>>> of variables that are input from an entry table, and then it just finds the
>>> the vars that are the closest to what is searching for all the vars. The
>>> closest code I have seen doing something similar is where there it is
>>> finding if an IP is in a certain range.
>>>
>>> Does that make sense? feel free to email me if you need more explanation.
>>>
>>> It is kind of like a multi variable search engine, that is finding the
>>> root cause of the symptoms that are the very best fit given the
>>> multi-variables...
>>>
>>> Thanks heaps for any assistance,
>>> Aslan.
>>>
>>>
>>>
>>>       
>> --
>> Jim Lucas
>>
>>   "Some men are born to greatness, some achieve greatness,
>>       and some have greatness thrust upon them."
>>
>> Twelfth Night, Act II, Scene V
>>    by William Shakespeare
>>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>>     
>
>   

--- End Message ---
--- Begin Message ---
I'm getting a lot of bogus requsts in the form of
"index.php?id=http://64.15.67.17/~babysona/logo.jpg?";, sometimes more than a
hundred a day per domain. The php script catches it, logs the request, sends
an email report and replies with "access denied", but it takes processing
which I'd rather not have php busy with. (The php script rejects anything
where id=something_not_numeric.) Is there a way for apache to catch these
requests before passing it to php? Is it more efficient for apache to handle
this than php?

Arno


--- End Message ---
--- Begin Message ---
Arno Kuhl wrote:

> Is there a
> way for apache to catch these requests before passing it to php? Is it
> more efficient for apache to handle this than php?

2 x yes. I think you could probably use <LocationMatch> and ban all
access with "Deny from all". 


/Per Jessen, Zürich


--- End Message ---
--- Begin Message ---
Arno Kuhl wrote:
I'm getting a lot of bogus requsts in the form of
"index.php?id=http://64.15.67.17/~babysona/logo.jpg?";, sometimes more than a
hundred a day per domain. The php script catches it, logs the request, sends
an email report and replies with "access denied", but it takes processing
which I'd rather not have php busy with. (The php script rejects anything
where id=something_not_numeric.) Is there a way for apache to catch these
requests before passing it to php? Is it more efficient for apache to handle
this than php?

Arno



Yes, in Apache turn off userdir access

In your httpd.conf file do this.

UserDir disabled

That way it will not process url that starts with a tildy ~...

That should take care of it. Apache should then only report a 404 error to the error log for the given virtual host.

--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare


--- End Message ---
--- Begin Message ---
On Wed, Jul 23, 2008 at 12:10 PM,  <[EMAIL PROTECTED]> wrote:
> Yes, sorry. I have a database that records ip of attacks on a customer
> server, what I like to do get a count so that I can see what subnet is
> doing the major of the attacks.
>
> select ip from ipslimit 10;
> +-----------------+-----------+
> | ip              | count(ip) |
> +-----------------+-----------+
> | 83.117.196.206  |         1 |
> | 85.17.109.28    |         1 |
> | 125.138.96.19   |         1 |
> | 89.110.148.253  |         1 |
> | 192.168.105.10  |         1 |
> | 200.170.124.72  |         1 |
> | 201.116.98.214  |         1 |
> | 202.168.255.226 |         1 |
> | 203.89.243.158  |         1 |
> | 210.245.207.217 |         1 |
> +-----------------+-----------+
> 10 rows in set (0.00 sec)

    Okay, this would have to be done in code, and isn't a MySQL issue.
 Presuming you're using PHP, I'm going to also copy this message to
the PHP General mailing list, Payne, so that others can benefit from
it in the archives as well.  If you're not already subscribed and
would like to follow along with the thread, please send a blank
message to [EMAIL PROTECTED]

    To get the Class C on that, here's a simple function you can use:

<?php
function get_subnet($ip) {
        return substr($ip,0,strrpos($ip,'.'));
}
?>

    As a quick illustration of how it works, here's an example script
(to use MySQL, just replace the $ips array with your <?php $row =
mysql_fetch_array($result); ?> or similar line):

<?php
$ips = 
array('192.168.0.0','10.0.0.1','127.0.0.1','216.37.159.240','99.99.99.99','127.0.0.2','192.168.1.1','10.0.0.0','192.168.0.1','192.168.0.150');

function get_subnet($ip) {
        return substr($ip,0,strrpos($ip,'.'));
}

foreach($ips as $ip) {
        echo $ip."'s Class C is ".get_subnet($ip)."\n";
}
?>


-- 
</Daniel P. Brown>
Better prices on dedicated servers:
Intel 2.4GHz/60GB/512MB/2TB $49.99/mo.
Intel 3.06GHz/80GB/1GB/2TB $59.99/mo.
Dedicated servers, VPS, and hosting from $2.50/mo.

--- End Message ---
--- Begin Message ---
I just want to point out that public IPs are no longer given out as
Class A, B, and C networks, but based on CIDR.  You can use rwhois to
figure out who has use of a certain subnet and what the range of it is.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Daniel Brown wrote:
> On Wed, Jul 23, 2008 at 12:10 PM,  <[EMAIL PROTECTED]> wrote:
>   
>> Yes, sorry. I have a database that records ip of attacks on a customer
>> server, what I like to do get a count so that I can see what subnet is
>> doing the major of the attacks.
>>
>> select ip from ipslimit 10;
>> +-----------------+-----------+
>> | ip              | count(ip) |
>> +-----------------+-----------+
>> | 83.117.196.206  |         1 |
>> | 85.17.109.28    |         1 |
>> | 125.138.96.19   |         1 |
>> | 89.110.148.253  |         1 |
>> | 192.168.105.10  |         1 |
>> | 200.170.124.72  |         1 |
>> | 201.116.98.214  |         1 |
>> | 202.168.255.226 |         1 |
>> | 203.89.243.158  |         1 |
>> | 210.245.207.217 |         1 |
>> +-----------------+-----------+
>> 10 rows in set (0.00 sec)
>>     
>
>     Okay, this would have to be done in code, and isn't a MySQL issue.
>  Presuming you're using PHP, I'm going to also copy this message to
> the PHP General mailing list, Payne, so that others can benefit from
> it in the archives as well.  If you're not already subscribed and
> would like to follow along with the thread, please send a blank
> message to [EMAIL PROTECTED]
>
>     To get the Class C on that, here's a simple function you can use:
>
> <?php
> function get_subnet($ip) {
>         return substr($ip,0,strrpos($ip,'.'));
> }
> ?>
>
>     As a quick illustration of how it works, here's an example script
> (to use MySQL, just replace the $ips array with your <?php $row =
> mysql_fetch_array($result); ?> or similar line):
>
> <?php
> $ips = 
> array('192.168.0.0','10.0.0.1','127.0.0.1','216.37.159.240','99.99.99.99','127.0.0.2','192.168.1.1','10.0.0.0','192.168.0.1','192.168.0.150');
>
> function get_subnet($ip) {
>         return substr($ip,0,strrpos($ip,'.'));
> }
>
> foreach($ips as $ip) {
>         echo $ip."'s Class C is ".get_subnet($ip)."\n";
> }
> ?>
>
>
>   

--- End Message ---
--- Begin Message ---
On Wed, 2008-07-23 at 01:21 -0700, Ted Wood wrote:
> On 23-Jul-08, at 1:19 AM, Ted Wood wrote:
> >
> > So PHP waits until a copy is actually needed before it makes one.  
> > Explicitly making copies incurs overhead because of the concept of  
> > "reference counting". So again, don't use references for performance  
> > reasons.
> 
> 
> That should've been:  Explicitly making "references", not copies...

This only applies to PHP5. PHP4's Copy-On-Write (COW) for objects was
crap and would clone the object on assignment. It was especially bad
when looping over an array of objects since each would be cloned so you
usually had to loop over the keys of the array and pull out a reference
yourself.

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


--- End Message ---
--- Begin Message ---
<?php
# So if i want a copy in PHP, like:

$a = $b;

# In PHP5 $a would still be a reference as long as $b is not being changed?(!)
# Such behaviour makes it extremely easy to write a speedy script
without worrying about copy/reference issues!

# Thanks to all of you,
# Ernie
?>

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

In both PHP 4 and PHP 5, this would be an internal reference:

$a = $b;

until $b is changed.

The only exception is with Object handling under PHP 4, which had flawed reference handling.

So, the rule remains -- don't use references for performance reasons -- use them if you need references. :-)


~Ted



On 23-Jul-08, at 1:20 PM, Yeti wrote:

<?php
# So if i want a copy in PHP, like:

$a = $b;

# In PHP5 $a would still be a reference as long as $b is not being changed?(!)
# Such behaviour makes it extremely easy to write a speedy script
without worrying about copy/reference issues!

# Thanks to all of you,
# Ernie
?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--- End Message ---
--- Begin Message ---
Can anyone point me in the right direction?  I know I am missing something
simple, but I can't place my hands on it.

$myCalTime = act_getCalendarDays($config, $myMonth, $myYear);

foreach($myCalTime as $calTime => $calArrayTime){
    $calArray[] = $calArrayTime['day']."=>array('NULL','linked-day
".strtolower($calArrayTime['reason'])."','".$calArrayTime['day']."'),";
}

act_getCalendarDays returns this....
Array
(
    [day] => Array
        (
            [0] => 05
            [1] => 06
            [2] => 26
            [3] => 27
        )

    [reason] => Array
        (
            [0] => Vacation
            [1] => Vacation
            [2] => Vacation
            [3] => Vacation
        )

)


What am I missing to get this
=>array('NULL=','linked-day ',''),

to look like this
05=>array(NULL,'linked-day vacation','05'),

--- End Message ---
--- Begin Message ---
Don't put the array definitions in quotes:
Should be either:

foreach($myCalTime as $calTime => $calArrayTime){
    $calArray[$calArrayTime['day']] = array('NULL','linked-day 
'.strtolower($calArrayTime['reason']),$calArrayTime['day']);

}

or

foreach($myCalTime as $calTime => $calArrayTime){
    $calArray[] = array($calArrayTime['day'] => array('NULL','linked-day 
'.strtolower($calArrayTime['reason']),$calArrayTime['day']));


Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Chris Ditty wrote:
> Can anyone point me in the right direction?  I know I am missing something
> simple, but I can't place my hands on it.
>
> $myCalTime = act_getCalendarDays($config, $myMonth, $myYear);
>
> foreach($myCalTime as $calTime => $calArrayTime){
>     $calArray[] = $calArrayTime['day']."=>array('NULL','linked-day
> ".strtolower($calArrayTime['reason'])."','".$calArrayTime['day']."'),";
> }
>
> act_getCalendarDays returns this....
> Array
> (
>     [day] => Array
>         (
>             [0] => 05
>             [1] => 06
>             [2] => 26
>             [3] => 27
>         )
>
>     [reason] => Array
>         (
>             [0] => Vacation
>             [1] => Vacation
>             [2] => Vacation
>             [3] => Vacation
>         )
>
> )
>
>
> What am I missing to get this
> =>array('NULL=','linked-day ',''),
>
> to look like this
> 05=>array(NULL,'linked-day vacation','05'),
>
>   

--- End Message ---
--- Begin Message ---
The array($calArrayTime..... is actually another string.  I am mainly trying to 
get the values for ['day']['0'], ['reason']['0'] etc all on the same line.

Sorry for not being clearer.

>>> Micah Gersten <[EMAIL PROTECTED]> 7/23/2008 2:50 PM >>>
Don't put the array definitions in quotes:
Should be either:

foreach($myCalTime as $calTime => $calArrayTime){
    $calArray[$calArrayTime['day']] = array('NULL','linked-day 
'.strtolower($calArrayTime['reason']),$calArrayTime['day']);

}

or

foreach($myCalTime as $calTime => $calArrayTime){
    $calArray[] = array($calArrayTime['day'] => array('NULL','linked-day 
'.strtolower($calArrayTime['reason']),$calArrayTime['day']));


Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com 



Chris Ditty wrote:
> Can anyone point me in the right direction?  I know I am missing something
> simple, but I can't place my hands on it.
>
> $myCalTime = act_getCalendarDays($config, $myMonth, $myYear);
>
> foreach($myCalTime as $calTime => $calArrayTime){
>     $calArray[] = $calArrayTime['day']."=>array('NULL','linked-day
> ".strtolower($calArrayTime['reason'])."','".$calArrayTime['day']."'),";
> }
>
> act_getCalendarDays returns this....
> Array
> (
>     [day] => Array
>         (
>             [0] => 05
>             [1] => 06
>             [2] => 26
>             [3] => 27
>         )
>
>     [reason] => Array
>         (
>             [0] => Vacation
>             [1] => Vacation
>             [2] => Vacation
>             [3] => Vacation
>         )
>
> )
>
>
> What am I missing to get this
> =>array('NULL=','linked-day ',''),
>
> to look like this
> 05=>array(NULL,'linked-day vacation','05'),
>
>   

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php 




MLGW now offers ONLINE BILLING!
To view your bills, receive paperless bills, 
check payment status and pay online,
go to www.mlgw.com and click on the My Account link.
Enroll today!


This e-mail and any attachments represent the views and opinions
of only the sender and are not necessarily those of 
Memphis Light, Gas & Water Division, and no such inference should be made.


--- End Message ---
--- Begin Message ---
On Wed, 2008-07-23 at 13:52 -0500, Chris Ditty wrote:
> Can anyone point me in the right direction?  I know I am missing something
> simple, but I can't place my hands on it.
> 
> $myCalTime = act_getCalendarDays($config, $myMonth, $myYear);
> 
> foreach($myCalTime as $calTime => $calArrayTime){
>     $calArray[] = $calArrayTime['day']."=>array('NULL','linked-day
> ".strtolower($calArrayTime['reason'])."','".$calArrayTime['day']."'),";
> }
> 
> act_getCalendarDays returns this....
> Array
> (
>     [day] => Array
>         (
>             [0] => 05
>             [1] => 06
>             [2] => 26
>             [3] => 27
>         )
> 
>     [reason] => Array
>         (
>             [0] => Vacation
>             [1] => Vacation
>             [2] => Vacation
>             [3] => Vacation
>         )
> 
> )
> 
> 
> What am I missing to get this
> =>array('NULL=','linked-day ',''),
> 
> to look like this
> 05=>array(NULL,'linked-day vacation','05'),

Your myCalTime isn't an array of arrays of arrays, like you're
suggesting in the foreach.

$calArray=array();
for($x=0;$x<sizeof($myCalTime["day"]);$x++) {
   $calArray[]=$myCalTime["day"][$x]."=>array('NULL','linked-day
".strtolower($myCalTime['reason'][$x])."','".$myCalTime['day'][$x]."'),";
}


--- End Message ---
--- Begin Message ---
I'm still confused.  What do you mean by same line?

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Chris Ditty wrote:
> The array($calArrayTime..... is actually another string.  I am mainly trying 
> to get the values for ['day']['0'], ['reason']['0'] etc all on the same line.
>
> Sorry for not being clearer.
>
>   
>>>> Micah Gersten <[EMAIL PROTECTED]> 7/23/2008 2:50 PM >>>
>>>>         
> Don't put the array definitions in quotes:
> Should be either:
>
> foreach($myCalTime as $calTime => $calArrayTime){
>     $calArray[$calArrayTime['day']] = array('NULL','linked-day 
> '.strtolower($calArrayTime['reason']),$calArrayTime['day']);
>
> }
>
> or
>
> foreach($myCalTime as $calTime => $calArrayTime){
>     $calArray[] = array($calArrayTime['day'] => array('NULL','linked-day 
> '.strtolower($calArrayTime['reason']),$calArrayTime['day']));
>
>
> Thank you,
> Micah Gersten
> onShore Networks
> Internal Developer
> http://www.onshore.com 
>
>
>
> Chris Ditty wrote:
>   
>> Can anyone point me in the right direction?  I know I am missing something
>> simple, but I can't place my hands on it.
>>
>> $myCalTime = act_getCalendarDays($config, $myMonth, $myYear);
>>
>> foreach($myCalTime as $calTime => $calArrayTime){
>>     $calArray[] = $calArrayTime['day']."=>array('NULL','linked-day
>> ".strtolower($calArrayTime['reason'])."','".$calArrayTime['day']."'),";
>> }
>>
>> act_getCalendarDays returns this....
>> Array
>> (
>>     [day] => Array
>>         (
>>             [0] => 05
>>             [1] => 06
>>             [2] => 26
>>             [3] => 27
>>         )
>>
>>     [reason] => Array
>>         (
>>             [0] => Vacation
>>             [1] => Vacation
>>             [2] => Vacation
>>             [3] => Vacation
>>         )
>>
>> )
>>
>>
>> What am I missing to get this
>> =>array('NULL=','linked-day ',''),
>>
>> to look like this
>> 05=>array(NULL,'linked-day vacation','05'),
>>
>>   
>>     
>
>   

--- End Message ---
--- Begin Message ---
Nice catch, I missed that.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Jason Norwood-Young wrote:
> On Wed, 2008-07-23 at 13:52 -0500, Chris Ditty wrote:
>   
>> Can anyone point me in the right direction?  I know I am missing something
>> simple, but I can't place my hands on it.
>>
>> $myCalTime = act_getCalendarDays($config, $myMonth, $myYear);
>>
>> foreach($myCalTime as $calTime => $calArrayTime){
>>     $calArray[] = $calArrayTime['day']."=>array('NULL','linked-day
>> ".strtolower($calArrayTime['reason'])."','".$calArrayTime['day']."'),";
>> }
>>
>> act_getCalendarDays returns this....
>> Array
>> (
>>     [day] => Array
>>         (
>>             [0] => 05
>>             [1] => 06
>>             [2] => 26
>>             [3] => 27
>>         )
>>
>>     [reason] => Array
>>         (
>>             [0] => Vacation
>>             [1] => Vacation
>>             [2] => Vacation
>>             [3] => Vacation
>>         )
>>
>> )
>>
>>
>> What am I missing to get this
>> =>array('NULL=','linked-day ',''),
>>
>> to look like this
>> 05=>array(NULL,'linked-day vacation','05'),
>>     
>
> Your myCalTime isn't an array of arrays of arrays, like you're
> suggesting in the foreach.
>
> $calArray=array();
> for($x=0;$x<sizeof($myCalTime["day"]);$x++) {
>    $calArray[]=$myCalTime["day"][$x]."=>array('NULL','linked-day
> ".strtolower($myCalTime['reason'][$x])."','".$myCalTime['day'][$x]."'),";
> }
>
>
>   

--- End Message ---
--- Begin Message ---
I actually got it.  Seeing Micah's code made me think.

Thanks for helping.  Much appreciated.

>>> Micah Gersten <[EMAIL PROTECTED]> 7/23/2008 3:06 PM >>>
Nice catch, I missed that.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com 



Jason Norwood-Young wrote:
> On Wed, 2008-07-23 at 13:52 -0500, Chris Ditty wrote:
>   
>> Can anyone point me in the right direction?  I know I am missing something
>> simple, but I can't place my hands on it.
>>
>> $myCalTime = act_getCalendarDays($config, $myMonth, $myYear);
>>
>> foreach($myCalTime as $calTime => $calArrayTime){
>>     $calArray[] = $calArrayTime['day']."=>array('NULL','linked-day
>> ".strtolower($calArrayTime['reason'])."','".$calArrayTime['day']."'),";
>> }
>>
>> act_getCalendarDays returns this....
>> Array
>> (
>>     [day] => Array
>>         (
>>             [0] => 05
>>             [1] => 06
>>             [2] => 26
>>             [3] => 27
>>         )
>>
>>     [reason] => Array
>>         (
>>             [0] => Vacation
>>             [1] => Vacation
>>             [2] => Vacation
>>             [3] => Vacation
>>         )
>>
>> )
>>
>>
>> What am I missing to get this
>> =>array('NULL=','linked-day ',''),
>>
>> to look like this
>> 05=>array(NULL,'linked-day vacation','05'),
>>     
>
> Your myCalTime isn't an array of arrays of arrays, like you're
> suggesting in the foreach.
>
> $calArray=array();
> for($x=0;$x<sizeof($myCalTime["day"]);$x++) {
>    $calArray[]=$myCalTime["day"][$x]."=>array('NULL','linked-day
> ".strtolower($myCalTime['reason'][$x])."','".$myCalTime['day'][$x]."'),";
> }
>
>
>   

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php 




MLGW now offers ONLINE BILLING!
To view your bills, receive paperless bills, 
check payment status and pay online,
go to www.mlgw.com and click on the My Account link.
Enroll today!


This e-mail and any attachments represent the views and opinions
of only the sender and are not necessarily those of 
Memphis Light, Gas & Water Division, and no such inference should be made.


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

I have a set of php scripts that handle the browsing and download of file from the server.

it has worked fine for a long time on a server linux, now I have got to migrate those scripts also on a windows server, and something very strange is happening:

the download process hangs when downloading big ( 50 MB and up ) files from the server, and the files are only partially downloaded.
the log on the server shows a Timer_connectionidle error message.

I'm quite sure it is a configuration ( php or IIS ) issue, but I have no idea about what could be the problem.

it is not an execution time problem since I have set the max_execution_time on the php.in to a very large value. it seems that the php script simply stops communicating with the server, and after a while the server kills it.

the original script used a readfile($filename) function, I have also tryed to replace it with fopen($filename, 'rb') and a while cicle with fread($filename, $chunksize), but with no success.

the server is Windows Server 2003 with IIS.

php Version is 5.2.5

any of you experienced a similar problem, or has any idea on what could be the problem?

Thanks,

     Giulio


Giulio Mastrosanti
[EMAIL PROTECTED]






--- End Message ---
--- Begin Message ---
On 7/23/08, Giulio Mastrosanti <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I have a set of php scripts that handle the browsing and download of file
> from the server.
>
> it has worked fine for a long time on a server linux, now I have got to
> migrate those scripts also on a windows server, and something very strange
> is happening:
>
> the download process hangs when  downloading big ( 50 MB and up ) files from
> the server, and the files are only partially downloaded.
> the log on the server shows a Timer_connectionidle error message.
>
> I'm quite sure it is a configuration ( php or IIS ) issue, but I have no
> idea about what could be the problem.
>
> it is not an execution time problem since I have set the max_execution_time
> on the php.in to a very large value.
> it seems that the php script simply stops communicating with the server, and
> after a while the server kills it.
>
> the original script used a  readfile($filename) function, I have also tryed
> to replace it with fopen($filename, 'rb') and a while cicle with
> fread($filename, $chunksize), but with no success.

I would recommend looking into a webserver that supports offloading
the file download to the webserver via fastcgi:

- nginx (preferred) using X-Accel-Redirect header
- lighttpd using X-Lighttpd-Sendfile header
- apache has a module mod_sendfile or something, but I don't recommend
apache for anything anymore

not sure if other webservers have it or not. But basically it allows
you to use PHP/application level logic to validate if the user has
access, and then tells the webserver "okay, now send the file" and
releases PHP/application level from having to spoonfeed the file using
things like readfile() and keeping the PHP thread/whatever open

--- End Message ---
--- Begin Message ---
I want to be able to do a getenv('SYMFONY_HOME'); or any env var that I've
setup in my /etc/bashrc for everyone. But apache obviously doesn't have a
shell, so it doesn't know about these. only the stuff in $_ENV. 

What I want to know is how can I read env vars like ANT_HOME, JAVA_HOME,
etc.. in php? I just need to be able to read symfony's root path so I can
stop hard coding it into a config file in the project everytime I deploy to
a new machine.
-- 
View this message in context: 
http://www.nabble.com/%24_ENV-or-getenv-to-get-bash-environmental-variables..-change-php.ini---env-vars-tp18617784p18617784.html
Sent from the PHP - General mailing list archive at Nabble.com.


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

I understand what you are trying to do. But as a web developer it is never a
good practice to have a insert query and page to display the record in the
same page. This way you will never add the redundant data whenever the page
is refreshed.

So from my experience I would suggest you do this:

form.php

if(isset($_GET['displayrecords']) && $_GET['displayrecords'] == "true") {
show records
}else{
<form action='qry_form.php'>
HTML FORM
submit
}

qry_form.php

{INSERT QUERY}

//redirect
header('location:form.php?displayrecords=true')

this intermediate step qry_form.php will insert the record and redirect to
the same page with a get variable.

This is a good practice to avoid inserting everytime you refresh the page.

Thanks




On Tue, Jul 22, 2008 at 8:12 AM, Daniel Brown <[EMAIL PROTECTED]> wrote:

> On Tue, Jul 22, 2008 at 10:51 AM, Rahul S. Johari
> <[EMAIL PROTECTED]> wrote:
> >
> > I just checked a couple of other browsers (IE, Safari, Opera) and it
> seems
> > to be working fine in all the browsers except Firefox 3. I think this
> issue
> > is now out of bounds for PHP - I don't think there is anything wrong in
> the
> > script or the way I'm doing this - I think the problem is lying somewhere
> in
> > either Firefox 3 or my settings of Firefox 3. Let me look into this.
>
>     If you believe that to be the case, Rahul, please report your
> findings at [EMAIL PROTECTED]  We (I'm a Mozilla
> developer as well) may then ask you to post portions of your
> 'about:config' to better troubleshoot the issues.
>
> --
> </Daniel P. Brown>
> Better prices on dedicated servers:
> Intel 2.4GHz/60GB/512MB/2TB $49.99/mo.
> Intel 3.06GHz/80GB/1GB/2TB $59.99/mo.
> Dedicated servers, VPS, and hosting from $2.50/mo.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---

Reply via email to