php-general Digest 5 Apr 2008 13:23:25 -0000 Issue 5387

Topics (messages 272558 through 272565):

Re: How to jump to line number in large file
        272558 by: Greg Bowser
        272563 by: Steve McGill
        272564 by: Richard Heyes

Re: using php to backup mysql database?
        272559 by: paragasu

Re: PostTrack Updates
        272560 by: Robert Cummings
        272561 by: Jim Lucas
        272562 by: Robert Cummings
        272565 by: Jason Pruim

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 ---
 fseek($handle, 1, SEEK_CUR);         // or fseek($handle, $pos)
  $t = fgetc($handle);

This probably won't help you, but given a quick glance, it looks like you're
incrementing the file pointer by 2 positions on each iteration of your while
loop. The fgetc() function returns the character at the current position and
increments the file pointer by 1.

I haven't tried this, but perhaps using strpos would be faster? Use strpos
to seek to find the first "\n", then use the offset parameter to seek to the
second, and so on, until strpos() returns false.

--GREG

--- End Message ---
--- Begin Message ---
Thanks for the heads up on fgetc() incrementing by one. I hadn't actually 
tested that code yet, I was using the original fseek($handle,$pos).

strpos would be ideal but it needs to work on a string and not a file - I 
don't want to load a 100Mb file into memory if I don't have to. Perhaps I 
should test how quick the fgets() and ftell() method is because at least it 
loads in one line at a time.

Does anybody know any other ways to go about the problem?

Many thanks,
Steve

""Greg Bowser"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> fseek($handle, 1, SEEK_CUR);         // or fseek($handle, $pos)
>  $t = fgetc($handle);
>
> This probably won't help you, but given a quick glance, it looks like 
> you're
> incrementing the file pointer by 2 positions on each iteration of your 
> while
> loop. The fgetc() function returns the character at the current position 
> and
> increments the file pointer by 1.
>
> I haven't tried this, but perhaps using strpos would be faster? Use strpos
> to seek to find the first "\n", then use the offset parameter to seek to 
> the
> second, and so on, until strpos() returns false.
>
> --GREG
> 



--- End Message ---
--- Begin Message ---
Thanks for the heads up on fgetc() incrementing by one. I hadn't actually tested that code yet, I was using the original fseek($handle,$pos).

strpos would be ideal but it needs to work on a string and not a file - I don't want to load a 100Mb file into memory if I don't have to. Perhaps I should test how quick the fgets() and ftell() method is because at least it loads in one line at a time.

Does anybody know any other ways to go about the problem?

Haven't read the rest of the thread, and so going by the subject alone, fgets() finishes when it encounters a newline, so you can use this wondrous fact to seek to a specific line:

<?php
    $fp  = fopen('filename', 'r');
    $num = 18; // Desired line number

    for ($i=0; $i<$num; $i++)
        $line = fgets($fp);

    echo $line;
?>

It works because fgets() stops when it encounters a newline (\n). So it's just a case of counting the calls to fgets().

--
Richard Heyes
Employ me:
http://www.phpguru.org/cv

--- End Message ---
--- Begin Message ---
On Sat, Apr 5, 2008 at 2:42 AM, Daniel Brown <[EMAIL PROTECTED]> wrote:

> On Fri, Apr 4, 2008 at 11:27 AM, paragasu <[EMAIL PROTECTED]> wrote:
> > anyone know how to backup a mysql database using PHP?
> >  i want to write one php function to allow admin to download the mysql
> >  database backup (mysqldump maybe?) ..
> >  and how to restore the database backup from web based admin?
> >
> >  i am using a shared server and the php scripts executed under the
> >  www-data user..
>
>     If you have shell access and/or can run system() calls from PHP
> (and presuming it's a *NIX-like system), you could try something like
> this:
>
> <?php
> // mysql-backup.php
>
> $database = "your-db-name";
> $username = "your-db-username";
> $password = "your-db-password";
> $stamp = time();
>
> ignore_user_abort(1); // Continue no matter what.
>
> exec('mysqldump -u '.$username.' -p'.$password.' '.$database.' >
> ./mysql_'.$stamp.'sql',$ret,$err);
> // Handle $ret and $err as you'd like, if you want.
>
> exec('tar -cf mysql_'.$stamp.'.tar mysql_'.$stamp.'.sql',$ret,$err);
> // Handle $ret and $err as you'd like, if you want.
>
> exec('gzip -9 mysql_'.$stamp.'.tar',$ret,$err);
> // Handle $ret and $err as you'd like, if you want.
>
> echo "<a href=\"mysql_".$stamp.".tar.gz\">Download MySQL Backup</a>";
> ?>
>
>    Doing any sanity, extension, or even concatenation of commands to
> a single line is up to you.
>
> --
> </Daniel P. Brown>
> Ask me about:
> Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
> and shared hosting starting @ $2.50/mo.
> Unmanaged, managed, and fully-managed!
>

thank you.. that is the answer i am looking for :)

--- End Message ---
--- Begin Message ---
<?php echo "On Fri, 2008-04-04 at 17:23 -0400, Daniel Brown wrote:\n" ?>
<?php echo "> Some changes take effect with the PostTrack metrics\n" ?>
<?php echo "> system with this week (will show up in next week's\n" ?>
<?php echo "> report). There's one bug fix and a new feature added,
\n" ?>
<?php echo "> in which some of you may be really interested.\n" ?>
<?php echo ">\n" ?>
<?php echo ">     CHANGELOG\n" ?>
<?php echo "\n" ?>
<?php echo ">         Fixed a bug that would (seemingly random)\n" ?>
<?php echo "> split a user's post recording over multiple entries.\n" ?>
<?php echo "> (See this week's report: Zoltan Nemeth for example)\n" ?>
<?php echo ">         Added a new CodeCount feature.  Explained\n" ?>
<?php echo ">         below.\n" ?>
<?php echo ">\n" ?>
<?php echo ">     The CodeCount feature will, from now on, track\n" ?>
<?php echo "> the amount of [pseudo]code everyone posts to the\n" ?>
<?php echo "> list. However, for a variety of reasons (including\n" ?>
<?php echo "> enforcing Good Coding Practices[tm], there will be\n" ?>
<?php echo "> some rules:\n" ?>
<?php echo ">\n" ?>
<?php echo ">         * short_open_tags code will not be counted.\n" ?>
<?php echo ">           It must begin with <?php, not <?, and\n" ?>
<?php echo ">           <?=\$variable;?> things won't count.\n" ?>
<?php echo ">         * All code must be properly closed as well as
\n" ?>
<?php echo ">           opened. Thus, <?php must be followed
by ?>.\n" ?>
<?php echo ">         * You can include multiple blocks of code,\n" ?>
<?php echo ">           and all will be tallied. So:\n" ?>
<?php echo ">             <?php\n" ?>
<?php echo ">                 // Block one\n" ?>
<?php echo ">             ?>\n" ?>
<?php echo ">             .... and ....\n" ?>
<?php echo ">             <?php\n" ?>
<?php echo ">                 // Block two\n" ?>
<?php echo ">             ?>\n" ?>
<?php echo ">             .... will both be counted.\n" ?>
<?php echo ">\n" ?>
<?php echo ">     Some notes that should be obvious:\n" ?>
<?php echo ">         * HTML won't be counted unless included in an
\n" ?>
<?php echo ">           echo/print construct or a HEREDOC/NOWDOC\n" ?>
<?php echo ">           (when used). Only the code between the\n" ?>
<?php echo ">           <?php and ?> tags will be counted.\n" ?>
<?php echo ">         * The CodeCount procedure *does* count\n" ?>
<?php echo ">           comments as code. This can be changed if\n" ?>
<?php echo ">           there's enough desire.\n" ?>
<?php echo ">         * CodeCount *will not* differentiate between\n" ?>
<?php echo ">           \"Good\" and \"Bad\" code. If you forget a\n" ?>
<?php echo ">           semicolon, it'll still count.\n" ?>
<?php echo ">\n" ?>
<?php echo "> --\n" ?>
<?php echo "> </Daniel P. Brown>\n" ?>
<?php echo "> Ask me about:\n" ?>
<?php echo "> Dedicated servers starting @ \$59.99/mo., VPS\n" ?>
<?php echo "> starting @ \$19.99/mo., and shared hosting starting @
\n" ?>
<?php echo "> \$2.50/mo. Unmanaged, managed, and fully-managed!\n" ?>

I don't know about anyone else, but I am absolutely stoked about this
development!

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


--- End Message ---
--- Begin Message ---
Robert Cummings wrote:
<?php echo "On Fri, 2008-04-04 at 17:23 -0400, Daniel Brown wrote:\n" ?>
<?php echo "> Some changes take effect with the PostTrack metrics\n" ?>
<?php echo "> system with this week (will show up in next week's\n" ?>
<?php echo "> report). There's one bug fix and a new feature added,
\n" ?>
<?php echo "> in which some of you may be really interested.\n" ?>
<?php echo ">\n" ?>
<?php echo ">     CHANGELOG\n" ?>
<?php echo "\n" ?>
<?php echo ">         Fixed a bug that would (seemingly random)\n" ?>
<?php echo "> split a user's post recording over multiple entries.\n" ?>
<?php echo "> (See this week's report: Zoltan Nemeth for example)\n" ?>
<?php echo ">         Added a new CodeCount feature.  Explained\n" ?>
<?php echo ">         below.\n" ?>
<?php echo ">\n" ?>
<?php echo ">     The CodeCount feature will, from now on, track\n" ?>
<?php echo "> the amount of [pseudo]code everyone posts to the\n" ?>
<?php echo "> list. However, for a variety of reasons (including\n" ?>
<?php echo "> enforcing Good Coding Practices[tm], there will be\n" ?>
<?php echo "> some rules:\n" ?>
<?php echo ">\n" ?>
<?php echo ">         * short_open_tags code will not be counted.\n" ?>
<?php echo ">           It must begin with <?php, not <?, and\n" ?>
<?php echo ">           <?=\$variable;?> things won't count.\n" ?>
<?php echo ">         * All code must be properly closed as well as
\n" ?>
<?php echo ">           opened. Thus, <?php must be followed
by ?>.\n" ?>
<?php echo ">         * You can include multiple blocks of code,\n" ?>
<?php echo ">           and all will be tallied. So:\n" ?>
<?php echo ">             <?php\n" ?>
<?php echo ">                 // Block one\n" ?>
<?php echo ">             ?>\n" ?>
<?php echo ">             .... and ....\n" ?>
<?php echo ">             <?php\n" ?>
<?php echo ">                 // Block two\n" ?>
<?php echo ">             ?>\n" ?>
<?php echo ">             .... will both be counted.\n" ?>
<?php echo ">\n" ?>
<?php echo ">     Some notes that should be obvious:\n" ?>
<?php echo ">         * HTML won't be counted unless included in an
\n" ?>
<?php echo ">           echo/print construct or a HEREDOC/NOWDOC\n" ?>
<?php echo ">           (when used). Only the code between the\n" ?>
<?php echo ">           <?php and ?> tags will be counted.\n" ?>
<?php echo ">         * The CodeCount procedure *does* count\n" ?>
<?php echo ">           comments as code. This can be changed if\n" ?>
<?php echo ">           there's enough desire.\n" ?>
<?php echo ">         * CodeCount *will not* differentiate between\n" ?>
<?php echo ">           \"Good\" and \"Bad\" code. If you forget a\n" ?>
<?php echo ">           semicolon, it'll still count.\n" ?>
<?php echo ">\n" ?>
<?php echo "> --\n" ?>
<?php echo "> </Daniel P. Brown>\n" ?>
<?php echo "> Ask me about:\n" ?>
<?php echo "> Dedicated servers starting @ \$59.99/mo., VPS\n" ?>
<?php echo "> starting @ \$19.99/mo., and shared hosting starting @
\n" ?>
<?php echo "> \$2.50/mo. Unmanaged, managed, and fully-managed!\n" ?>

I don't know about anyone else, but I am absolutely stoked about this
development!

Cheers,
Rob.

wait you forgot the semi-colon... ah, that's right, he said grammar mistakes were not counted...

:)

Who else........

--- End Message ---
--- Begin Message ---
On Fri, 2008-04-04 at 22:39 -0700, Jim Lucas wrote:
> Robert Cummings wrote:
> > <?php echo "On Fri, 2008-04-04 at 17:23 -0400, Daniel Brown wrote:\n" ?>
> > <?php echo "> Some changes take effect with the PostTrack metrics\n" ?>
> > <?php echo "> system with this week (will show up in next week's\n" ?>
> > <?php echo "> report). There's one bug fix and a new feature added,
> > \n" ?>
> > <?php echo "> in which some of you may be really interested.\n" ?>
> > <?php echo ">\n" ?>
> > <?php echo ">     CHANGELOG\n" ?>
> > <?php echo "\n" ?>
> > <?php echo ">         Fixed a bug that would (seemingly random)\n" ?>
> > <?php echo "> split a user's post recording over multiple entries.\n" ?>
> > <?php echo "> (See this week's report: Zoltan Nemeth for example)\n" ?>
> > <?php echo ">         Added a new CodeCount feature.  Explained\n" ?>
> > <?php echo ">         below.\n" ?>
> > <?php echo ">\n" ?>
> > <?php echo ">     The CodeCount feature will, from now on, track\n" ?>
> > <?php echo "> the amount of [pseudo]code everyone posts to the\n" ?>
> > <?php echo "> list. However, for a variety of reasons (including\n" ?>
> > <?php echo "> enforcing Good Coding Practices[tm], there will be\n" ?>
> > <?php echo "> some rules:\n" ?>
> > <?php echo ">\n" ?>
> > <?php echo ">         * short_open_tags code will not be counted.\n" ?>
> > <?php echo ">           It must begin with <?php, not <?, and\n" ?>
> > <?php echo ">           <?=\$variable;?> things won't count.\n" ?>
> > <?php echo ">         * All code must be properly closed as well as
> > \n" ?>
> > <?php echo ">           opened. Thus, <?php must be followed
> > by ?>.\n" ?>
> > <?php echo ">         * You can include multiple blocks of code,\n" ?>
> > <?php echo ">           and all will be tallied. So:\n" ?>
> > <?php echo ">             <?php\n" ?>
> > <?php echo ">                 // Block one\n" ?>
> > <?php echo ">             ?>\n" ?>
> > <?php echo ">             .... and ....\n" ?>
> > <?php echo ">             <?php\n" ?>
> > <?php echo ">                 // Block two\n" ?>
> > <?php echo ">             ?>\n" ?>
> > <?php echo ">             .... will both be counted.\n" ?>
> > <?php echo ">\n" ?>
> > <?php echo ">     Some notes that should be obvious:\n" ?>
> > <?php echo ">         * HTML won't be counted unless included in an
> > \n" ?>
> > <?php echo ">           echo/print construct or a HEREDOC/NOWDOC\n" ?>
> > <?php echo ">           (when used). Only the code between the\n" ?>
> > <?php echo ">           <?php and ?> tags will be counted.\n" ?>
> > <?php echo ">         * The CodeCount procedure *does* count\n" ?>
> > <?php echo ">           comments as code. This can be changed if\n" ?>
> > <?php echo ">           there's enough desire.\n" ?>
> > <?php echo ">         * CodeCount *will not* differentiate between\n" ?>
> > <?php echo ">           \"Good\" and \"Bad\" code. If you forget a\n" ?>
> > <?php echo ">           semicolon, it'll still count.\n" ?>
> > <?php echo ">\n" ?>
> > <?php echo "> --\n" ?>
> > <?php echo "> </Daniel P. Brown>\n" ?>
> > <?php echo "> Ask me about:\n" ?>
> > <?php echo "> Dedicated servers starting @ \$59.99/mo., VPS\n" ?>
> > <?php echo "> starting @ \$19.99/mo., and shared hosting starting @
> > \n" ?>
> > <?php echo "> \$2.50/mo. Unmanaged, managed, and fully-managed!\n" ?>
> > 
> > I don't know about anyone else, but I am absolutely stoked about this
> > development!
> > 
> > Cheers,
> > Rob.
> 
> wait you forgot the semi-colon...  ah, that's right, he said grammar 
> mistakes were not counted...

Perfectly valid to omit the last semi-colon when closing a PHP block.

> :)

;)

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


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

On Apr 5, 2008, at 1:48 AM, Robert Cummings wrote:


On Fri, 2008-04-04 at 22:39 -0700, Jim Lucas wrote:
Robert Cummings wrote:
<?php echo "On Fri, 2008-04-04 at 17:23 -0400, Daniel Brown wrote: \n" ?> <?php echo "> Some changes take effect with the PostTrack metrics \n" ?> <?php echo "> system with this week (will show up in next week's \n" ?>
<?php echo "> report). There's one bug fix and a new feature added,
\n" ?>
<?php echo "> in which some of you may be really interested.\n" ?>
<?php echo ">\n" ?>
<?php echo ">     CHANGELOG\n" ?>
<?php echo "\n" ?>
<?php echo "> Fixed a bug that would (seemingly random) \n" ?> <?php echo "> split a user's post recording over multiple entries. \n" ?> <?php echo "> (See this week's report: Zoltan Nemeth for example) \n" ?> <?php echo "> Added a new CodeCount feature. Explained \n" ?>
<?php echo ">         below.\n" ?>
<?php echo ">\n" ?>
<?php echo "> The CodeCount feature will, from now on, track \n" ?>
<?php echo "> the amount of [pseudo]code everyone posts to the\n" ?>
<?php echo "> list. However, for a variety of reasons (including \n" ?> <?php echo "> enforcing Good Coding Practices[tm], there will be \n" ?>
<?php echo "> some rules:\n" ?>
<?php echo ">\n" ?>
<?php echo "> * short_open_tags code will not be counted. \n" ?>
<?php echo ">           It must begin with <?php, not <?, and\n" ?>
<?php echo ">           <?=\$variable;?> things won't count.\n" ?>
<?php echo ">         * All code must be properly closed as well as
\n" ?>
<?php echo ">           opened. Thus, <?php must be followed
by ?>.\n" ?>
<?php echo "> * You can include multiple blocks of code, \n" ?>
<?php echo ">           and all will be tallied. So:\n" ?>
<?php echo ">             <?php\n" ?>
<?php echo ">                 // Block one\n" ?>
<?php echo ">             ?>\n" ?>
<?php echo ">             .... and ....\n" ?>
<?php echo ">             <?php\n" ?>
<?php echo ">                 // Block two\n" ?>
<?php echo ">             ?>\n" ?>
<?php echo ">             .... will both be counted.\n" ?>
<?php echo ">\n" ?>
<?php echo ">     Some notes that should be obvious:\n" ?>
<?php echo ">         * HTML won't be counted unless included in an
\n" ?>
<?php echo "> echo/print construct or a HEREDOC/NOWDOC \n" ?>
<?php echo ">           (when used). Only the code between the\n" ?>
<?php echo ">           <?php and ?> tags will be counted.\n" ?>
<?php echo ">         * The CodeCount procedure *does* count\n" ?>
<?php echo "> comments as code. This can be changed if \n" ?>
<?php echo ">           there's enough desire.\n" ?>
<?php echo "> * CodeCount *will not* differentiate between \n" ?> <?php echo "> \"Good\" and \"Bad\" code. If you forget a \n" ?>
<?php echo ">           semicolon, it'll still count.\n" ?>
<?php echo ">\n" ?>
<?php echo "> --\n" ?>
<?php echo "> </Daniel P. Brown>\n" ?>
<?php echo "> Ask me about:\n" ?>
<?php echo "> Dedicated servers starting @ \$59.99/mo., VPS\n" ?>
<?php echo "> starting @ \$19.99/mo., and shared hosting starting @
\n" ?>
<?php echo "> \$2.50/mo. Unmanaged, managed, and fully-managed! \n" ?>

I don't know about anyone else, but I am absolutely stoked about this
development!

Cheers,
Rob.

wait you forgot the semi-colon...  ah, that's right, he said grammar
mistakes were not counted...

Perfectly valid to omit the last semi-colon when closing a PHP block.

<?PHP echo 'So does the new code count all quoted code as well? :)';?>
<?PHP echo 'If so... Then we are going to have a ton of code to start with!';?>




:)

;)

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


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




--- End Message ---

Reply via email to