php-general Digest 27 Sep 2008 15:42:22 -0000 Issue 5705

Topics (messages 281020 through 281037):

Re: The Data Literacy Test: Interpretation Added
        281020 by: Shelley
        281021 by: Shelley
        281022 by: Robert Cummings

event feeder
        281023 by: Alain Roger

Re: Sepating MySQL result set into html tables
        281024 by: Thodoris

Prevent execution bad commands
        281025 by: Manoj Singh
        281031 by: Ashley Sheridan
        281033 by: Lupus Michaelis

PHP + Cron jobs
        281026 by: Waynn Lue
        281027 by: Per Jessen
        281028 by: Waynn Lue
        281029 by: Per Jessen
        281030 by: Waynn Lue
        281032 by: Per Jessen
        281034 by: Thodoris

Re: Questions regarding limits of processes launched by system, exec,           
     passthru ...
        281035 by: Thodoris
        281037 by: Thodoris

Regular Expression Backreference in subpattern.
        281036 by: Shiplu

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 ---
Actually, I think the author meant that you already read through those books
and learned those terms,
rather than mean that you are cheating on the test.

As the author recommended you read the books listed below if you are not an
expert yet.

Those recommended books are also added on the interpretation page for your
reference.

2008/9/26 Robert Cummings <[EMAIL PROTECTED]>

> On Fri, 2008-09-26 at 14:02 +0800, Shelley wrote:
> > Fyi,
> >
> > The interpretation of the score is added.
> > Welcome to check your programming knowledge level:
> >
> http://www.phparch.cn/index.php/php/34-php-basics/202-the-data-literacy-test
> >
> > :)
>
> >From the interpretation:
>
>    20–24   You are an expert programmer. You probably already have
>            the books listed below on your shelf.
>
> *lol* Why would "probably" be applicable in this scenario? More likely
> most people hit up google to answer their questions.
>
> Cheers,
> Rob.
> --
> http://www.interjinn.com
> Application and Templating Framework for PHP
>
>


-- 
With best regards,
Shelley Shyan
http://phparch.cn

--- End Message ---
--- Begin Message ---
2008/9/26 tedd <[EMAIL PROTECTED]>

> At 2:02 PM +0800 9/26/08, Shelley wrote:
>
>> Fyi,
>>
>> The interpretation of the score is added.
>> Welcome to check your programming knowledge level:
>>
>> http://www.phparch.cn/index.php/php/34-php-basics/202-the-data-literacy-test
>>
>> :)
>>
>
> The answer as I see it is 27.
>
> While we both agree that "elongated stream," "retroactive synapse," and
> "value chain" are false computer terms,



> there are three that you apparently don't know.

??? What is "three", excuse me?


> Would you care point those out so we can discuss them?
>
> This reminds me of a survey I conducted in the late 80's where I had
> section of computer terms for people to indicate what was familiar, or not.
> The answer of each was either "I heard of it", "I know it", or "Huh?"
>
> I used that answer to test the "truth" of the person taking the survey.
> Interesting enough, I found the ratio of "truth" was equally spread between
> all age groups. In other words, the 20-30, 31-40, 41-50, 51-60 age groups
> all had the same ratio of people reporting a false term as "I know it."
>
> 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
>
>


-- 
With best regards,
Shelley Shyan
http://phparch.cn

--- End Message ---
--- Begin Message ---
On Sat, 2008-09-27 at 13:02 +0800, Shelley wrote:
> Actually, I think the author meant that you already read through those books
> and learned those terms,
> rather than mean that you are cheating on the test.
> 
> As the author recommended you read the books listed below if you are not an
> expert yet.
> 
> Those recommended books are also added on the interpretation page for your
> reference.

No, what I was getting at was that I knew almost all the terms and don't
think I've read any of the books... possibly the first in university but
I can't remember and the book is buried in a box someplace. These days
one can learn all the information contained in the books via the web.
BTW, I thought value chain was a real concept but you indicate it is
garbage. In OOP many would consider the following to be a value chain:

    $foo->fee->fii->foo->fum

I didn't consider myself pompous at all for that interpretation.

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


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

i would like to display on my web application, the latest 3 events added to
my web DB.
something like latest 3 event which happen to company.

what is the best way knowing that each event is translated in several
languages and stored into DB ?
should i directly read latest 3 events from DB using PHP ?
should i firstly query DB for each language, store the result into a txt
file (for example) and after using AJAX or PHP read this file ?

what do you use usally ?
thx.

-- 
Alain
------------------------------------
Windows XP SP3
PostgreSQL 8.2.4 / MS SQL server 2005
Apache 2.2.4
PHP 5.2.4
C# 2005-2008

--- End Message ---
--- Begin Message ---
O/H Robert Cummings ??????:
On Fri, 2008-09-26 at 14:41 -0400, Robert Cummings wrote:
On Fri, 2008-09-26 at 21:23 +0300, Thodoris wrote:
On Fri, 2008-09-26 at 13:50 -0400, [EMAIL PROTECTED] wrote:
Might I suggest you count the fields and divide it by the cols you want to display? Example
$forest = mysql_query("SELECT * FROM your_table");
$gump = mysql_num_fields($forest);

First of all the problem is with the rows not the columns. The problem is that I want to divide the rows into equal (or anything close to that) chunks and put every chunk in a separate table.

There I said it :-) .

Because I know my table contains 15 rows I can do this.
$tulip = floor($gump /5);
You can count the rows (not the cols) in the result set but you can't base your algorithm on that only.

The problem is that if for e.g. you have 91 rows and you want to divide it into 3 you will have three chunks of 30 like this:

30, 30, 31

You have a bug if you have 16 rows.
In my case I really don't care in what table the extra row goes.
The solution is pretty easy, I just don't have time right now to write
it for you. Either way, I would approach the problem inverseley to your
current solution. Instead of traversing the rows and performing internal
calculations, I'd calculate the tables and rows needed and then traverse
that information and in the innermost loop traverse the result set using
the next() function.

<?php

$cells = array( 'First', 'Second' );
$items = array( array( 'one', 'two' ), array( 'one', 'two' ),
array( 'one', 'two' ), array( 'one', 'two' ), array( 'one', 'two' ), arr

$numTables = 3;
$items = array_chunk( $items, ceil( count( $items ) / $numTables ) );

$html = '';
foreach( $items as $tableItems )
{
    if( $tableItems )
    {
        $html .= '<table><tr>';

        foreach( $cells as $cell )
        {
            $html .= '<td>'.$cell.'</td>';
        }

        $html .= '</tr>';

        foreach( $tableItems as $rowItems )
        {
            $html .= '<tr>';

            foreach( $rowItems as $item )
            {
                $html .= '<td>'.$item.'</td>';
            }

            $html .= '</tr>';
        }

        $html .= '</table>';
    }
}

?>

I changed my mind on how I wanted to do it. Either way... simple
enough :) Adapt to fit your own scenario.

Cheers,
Rob.
Thanks guys for all the responses. Especially Rob showed me the magical use of the array_chunk function which I was tending to ignore :-) .

-------
Thodoris



--- End Message ---
--- Begin Message ---
Hi All,
I am developing a web page where i have to display the files list based on
some search criteria and of certain duration. My web server is on linux
operating system. The command i am using for this peropse is:

find /home/test -mtime -$duration | sort | xargs grep -l "$search_criteria"

Is any malicious user can use the search criteria to perform some bad
commands in the operating system.

If it is then please suggest how to prevent it.

Please help me out.

Best Regards,
Manoj Kumar Singh

--- End Message ---
--- Begin Message ---
On Sat, 2008-09-27 at 14:45 +0530, Manoj Singh wrote:
> Hi All,
> I am developing a web page where i have to display the files list based on
> some search criteria and of certain duration. My web server is on linux
> operating system. The command i am using for this peropse is:
> 
> find /home/test -mtime -$duration | sort | xargs grep -l "$search_criteria"
> 
> Is any malicious user can use the search criteria to perform some bad
> commands in the operating system.
> 
> If it is then please suggest how to prevent it.
> 
> Please help me out.
> 
> Best Regards,
> Manoj Kumar Singh
It's likely yes, unless you validate the search criteria in any way,
you're just asking for trouble.


Ash
www.ashleysheridan.co.uk


--- End Message ---
--- Begin Message ---
Ashley Sheridan a écrit :

find /home/test -mtime -$duration | sort | xargs grep -l "$search_criteria"

It's likely yes, unless you validate the search criteria in any way,
you're just asking for trouble.

  I just add an exemple that delete evérything on your server :

$searh_criteria = "`rm -rf /`" ;

It exists a function <http://fr2.php.net/manual/en/function.escapeshellcmd.php> that escape shuch kind of string.
--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org

--- End Message ---
--- Begin Message ---
This is something that I've noticed for awhile, but last post to this
mailing list reminded me that someone probably already knows how to work
around this!  I have a cron job that looks something like

12 6 * * * php /home/foo/temp.php

But even if temp.php doesn't output anything, I still get emails from the
crontab that consist of

"Content-type: text/html"

I assume this is happening because it's interpreting as a web page or some
such.  Is there a better way to set the crontab so I don't get that output?

Thanks,
Waynn

--- End Message ---
--- Begin Message ---
Waynn Lue wrote:

> This is something that I've noticed for awhile, but last post to this
> mailing list reminded me that someone probably already knows how to
> work
> around this!  I have a cron job that looks something like
> 
> 12 6 * * * php /home/foo/temp.php
> 
> But even if temp.php doesn't output anything, I still get emails from
> the crontab that consist of
> 
> "Content-type: text/html"
> 
> I assume this is happening because it's interpreting as a web page or
> some such. 

Somehow your /home/foo/temp.php isn't running with the correct PHP
interpreter. 

> Is there a better way to set the crontab so I don't get that 
> output?

You can always use MAILTO= to direct any output from a cronjob.


/Per Jessen, Zürich


--- End Message ---
--- Begin Message ---
>
> > This is something that I've noticed for awhile, but last post to this
> > mailing list reminded me that someone probably already knows how to
> > work
> > around this!  I have a cron job that looks something like
> >
> > 12 6 * * * php /home/foo/temp.php
> >
> > But even if temp.php doesn't output anything, I still get emails from
> > the crontab that consist of
> >
> > "Content-type: text/html"
> >
> > I assume this is happening because it's interpreting as a web page or
> > some such.
>
> Somehow your /home/foo/temp.php isn't running with the correct PHP
> interpreter.
>
> > Is there a better way to set the crontab so I don't get that
> > output?
>
> You can always use MAILTO= to direct any output from a cronjob.
>
I actually am using MAILTO, and that's where the problem is.  A cronjob only
mails when there actually is output, which I'm fine with.  In fact, when I
run php temp.php from the command line, I don't get any output.  But when
it's part of the cronjob, there's that content-type output, which triggers
mail to me.

You mentioned a correct php interpreter above.  Should I instead be running
php through some other way or with a specific flag?

Waynn

--- End Message ---
--- Begin Message ---
Waynn Lue wrote:

> I actually am using MAILTO, and that's where the problem is.  A
> cronjob only mails when there actually is output, which I'm fine with. 
> In fact, when I run php temp.php from the command line, I don't get
> any output.  But when it's part of the cronjob, there's that
> content-type output, which triggers mail to me.
> 
> You mentioned a correct php interpreter above.  Should I instead be
> running php through some other way or with a specific flag?

Check what 'php -v' says when you run it from the command-line - it
shuold be something like this:

php -v
PHP 5.2.4 with Suhosin-Patch 0.9.6.2 (cli) (built: Sep 22 2007 02:01:31)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

I suspect yours might be saying 'cgi' instead of 'cli' ?


/Per Jessen, Zürich


--- End Message ---
--- Begin Message ---
Hm looks like it's CLI.

$ php -v
PHP 5.2.6 (cli) (built: Aug 11 2008 13:36:00)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
    with Advanced PHP Debugger (APD) v0.9, , by George Schlossnagle

--- End Message ---
--- Begin Message ---
Waynn Lue wrote:

> Hm looks like it's CLI.
> 
> $ php -v
> PHP 5.2.6 (cli) (built: Aug 11 2008 13:36:00)
> Copyright (c) 1997-2008 The PHP Group
> Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
>     with Advanced PHP Debugger (APD) v0.9, , by George Schlossnagle

Yep, looks good - check that your cron script is also running with that
interpreter.  I can't really think of why it wouldn't be, but ...


/Per Jessen, Zürich


--- End Message ---
--- Begin Message ---
O/H Waynn Lue ??????:
This is something that I've noticed for awhile, but last post to this
mailing list reminded me that someone probably already knows how to work
around this!  I have a cron job that looks something like

12 6 * * * php /home/foo/temp.php

But even if temp.php doesn't output anything, I still get emails from the
crontab that consist of

"Content-type: text/html"

I assume this is happening because it's interpreting as a web page or some
such.  Is there a better way to set the crontab so I don't get that output?

Thanks,
Waynn

Perhaps this would do the job much better.

12 6 * * * php -f /home/foo/temp.php


Also consider an alternative solution. Add this on the first line of the php script:

#! /usr/bin/php

And make it executable and then put into cron this:

12 6 * * * /home/foo/temp.php


This is if it is an execution problem.

In case you have defined MAILTO directive in the crontab then anything that is executed by cron will mail you the results.
This comes from crons man page:

If MAILTO is defined (and non-empty), mail is sent to the user so named. If MAILTO is defined but empty (MAILTO=""), no mail will be sent.
Otherwise mail is sent to the owner of the crontab.
By default, cron will send mail using the mail ’Content-Type:’ header of ’text/plain’ with the ’charset=’ parameter set to the charmap / codeset of the
locale in which crond(8) is started up



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

Hello all,

Is there a way to limit the memory consumption and / or the CPU
consumption of processes launched by the php functions system,
exec, passthru, proc_open and shell_exec?

We use mod_php with an apache (mpm-prefork) on Linux.

The following settings don't have any effect at all:
PHP:
  max_execution_time 30
  memory_limit 8M
Apache:
  RLimitCPU 30 30
  RLimitMEM 8388608 8388608

The limits above do have effect on php-scripts (without system calls)
and on CGIs (as well on processes launched by CGIs).

Any Ideas?

Kind Regards
valli


PS: I tested it with the following two scripts:
system_memorytest.php
=====================
<html>
<head>
  <title>php-systemcall-memory test</title>
</head>
<body>
  php-systemcall-memory test<br>
  ... and here's the system call:<br>
  <pre>
<?php
   $cmd = '/usr/bin/perl -e \'
      $| = 1;
      print "start of the systemcall<br>\n";
      $s = "teststr_";
      while (1) {
         print "len=".length($s)."<br>\n";
         sleep(1);
         $s .= $s;
      }
   \'';
   print htmlspecialchars($cmd);
?>
  </pre>
<?php
  ob_flush();
  flush();
  system($cmd);
?>
</body>
</html>


system_timeouttest.php
======================
<html>
<head>
  <title>php-systemcall-timeout test</title>
</head>
<body>
  php-systemcall-timeout test<br>
  ... and here's the system call:<br>
  <pre>
<?php
   $cmd = '/usr/bin/perl -e \'
      $| = 1;
      print "start of the systemcall<br>\n";
      $i = 0;
      while (1) {
         if (($i % 10000000) == 0) {
            print "i=".$i."<br>\n";
         }
         $i += 1;
      }
   \'';
   print htmlspecialchars($cmd);
?>
  </pre>
<?php
  ob_flush();
  flush();
  system($cmd);
?>
</body>
</html>





Well as far as I know there are already memory limits to every php process and you define this in php.ini. I recently made a script that used to exhaust all the given memory and I needed to increase the limit.

memory_limit = 16M

You can change this to whatever you wish to control. You can also change these if you want to control execution time:

max_execution_time = 30 ; Maximum execution time of each script, in seconds max_input_time = 60 ; Maximum amount of time each script may spend parsing request data


I haven't seen a way to control disk access space but I guess there are two ways to do that. One is quota the space that php writes in or do this by the programming way (meaning that you may check the space before you write something).

As for the CPU I think there are OS specific techniques to control resource usage in general but it depends on what *nix system you use (FreeBSD, Linux etc).


------------
Thodoris

--- End Message ---
--- Begin Message ---
O/H Thodoris έγραψε:

Hello all,

Is there a way to limit the memory consumption and / or the CPU
consumption of processes launched by the php functions system,
exec, passthru, proc_open and shell_exec?

We use mod_php with an apache (mpm-prefork) on Linux.

The following settings don't have any effect at all:
PHP:
  max_execution_time 30
  memory_limit 8M
Apache:
  RLimitCPU 30 30
  RLimitMEM 8388608 8388608

The limits above do have effect on php-scripts (without system calls)
and on CGIs (as well on processes launched by CGIs).

Any Ideas?

Kind Regards
valli


PS: I tested it with the following two scripts:
system_memorytest.php
=====================
<html>
<head>
  <title>php-systemcall-memory test</title>
</head>
<body>
  php-systemcall-memory test<br>
  ... and here's the system call:<br>
  <pre>
<?php
   $cmd = '/usr/bin/perl -e \'
      $| = 1;
      print "start of the systemcall<br>\n";
      $s = "teststr_";
      while (1) {
         print "len=".length($s)."<br>\n";
         sleep(1);
         $s .= $s;
      }
   \'';
   print htmlspecialchars($cmd);
?>
  </pre>
<?php
  ob_flush();
  flush();
  system($cmd);
?>
</body>
</html>


system_timeouttest.php
======================
<html>
<head>
  <title>php-systemcall-timeout test</title>
</head>
<body>
  php-systemcall-timeout test<br>
  ... and here's the system call:<br>
  <pre>
<?php
   $cmd = '/usr/bin/perl -e \'
      $| = 1;
      print "start of the systemcall<br>\n";
      $i = 0;
      while (1) {
         if (($i % 10000000) == 0) {
            print "i=".$i."<br>\n";
         }
         $i += 1;
      }
   \'';
   print htmlspecialchars($cmd);
?>
  </pre>
<?php
  ob_flush();
  flush();
  system($cmd);
?>
</body>
</html>





Well as far as I know there are already memory limits to every php process and you define this in php.ini. I recently made a script that used to exhaust all the given memory and I needed to increase the limit.

memory_limit = 16M

You can change this to whatever you wish to control. You can also change these if you want to control execution time:

max_execution_time = 30 ; Maximum execution time of each script, in seconds max_input_time = 60 ; Maximum amount of time each script may spend parsing request data


I haven't seen a way to control disk access space but I guess there are two ways to do that. One is quota the space that php writes in or do this by the programming way (meaning that you may check the space before you write something).

As for the CPU I think there are OS specific techniques to control resource usage in general but it depends on what *nix system you use (FreeBSD, Linux etc).


------------
Thodoris


Sorry for the mistake I misread the original question.

The fact is that if I am correct when you call something using system a different process is handling this so you can do this only using the OS. In this case php.ini has no effect.
--- End Message ---
--- Begin Message ---
The string is "<td>charge</td><td>100</td>".
I want and array( "charge"=>100).
I am using this regular expression,
'/<td>([^<]+)<\/td><td>(?P<\1>\d+)<\/td>/'.


But its not working..

I get this error.,
PHP Warning:  preg_match(): Compilation failed: syntax error after (?P
at offset 25 in E:\src\php\WebEngine\- on line 4

any idea?

-- 
Blog: http://talk.cmyweb.net/
Follow me: http://twitter.com/shiplu

--- End Message ---

Reply via email to