SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jul 2003
    Location
    IL
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .php files on the fly

    Here's the deal.. I'm not really a beginner programmer, but I'm just now starting to get into the more technical side of php.

    I own/run myownjournal.com an online blog site. Users can set custom settings for their journals and it's all stored in the database. The database is getting TONS of traffic, and I want to reduce it some. So here is my planning.

    I want to create config files for each user storing their settings in there. So I could just include a file called user_settings.php in their journal.

    To first create these files I would have to create them from nothing. I would pull the information they have in the database, and write it to a file, and save it on my server.

    What would be the way to do this? It's my first time ever attempting anything like this and I'm kind of lost.

    Any help would be great!

    Thanks

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I woudl be very weary going from a database implementation to a file one, because maintaining all of those files is not going to be fun. If you haven't done so already, I suggest you try to optimize your site first to reduce database traffic. Use persistant connections, add indexes, etc.

    The other thing you could do is create a cache file in each user's directory that is recreated from the database every time the user updates the settings. But you keep the data in the database too so that you can easily regenerate the files if you want to change formats or anything. If you wanted to change something in the settings file and you didn't have a database backup, you'd have to do weird data parsing on each file to update them.
    ck :: bringing chris to the masses.

  3. #3
    Hi there! Owen's Avatar
    Join Date
    Jan 2000
    Location
    CA
    Posts
    1,165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about caching the generated pages? Take a look at the (gosh) PEAR module Cache::Lite. It's easy to use and you only need to add a couple of lines to speed things up. After all, who cares if their page is 5 minutes out of date?

    Owen

  4. #4
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    I've been thinking of doing something like this one something I'm working on.
    If I do it, I'll probably just have a configuration table in the DB that only has one row.
    Then I'll just select the row from the DB, and write the values to a .php file.

    Here's a real simple(untested) example:

    PHP Code:


    <?php

    $result 
    mysql_query("SELECT * FROM config");
    $row mysql_fetch_assoc($result);

    $fp fopen('/file/to/config.php''w');

    fwrite($fp'$CONFIG[\'var1\'] = '.$row['columnName1'].";\n");
    fwrite($fp'$CONFIG[\'var2\'] = '.$row['columnName2'].";\n");
    fwrite($fp'$CONFIG[\'var3\'] = '.$row['columnName3'].";\n");
    fwrite($fp'$CONFIG[\'var4\'] = '.$row['columnName4'].";\n");
    fwrite($fp'$CONFIG[\'var5\'] = '.$row['columnName5'].";\n");
    fwrite($fp'$CONFIG[\'var6\'] = '.$row['columnName6'].";\n");
    fwrite($fp'$CONFIG[\'var7\'] = '.$row['columnName7'].";\n");

    /* 
    Could also use DEFINE:

    fwrite($fp, 'DEFINE(\'CONST_NAME\', '.$row['columnName'].")\n");

    */

    fclose($fp);

    ?>

    BUt if you're caching the output with something like Pear::Cache_Lite , I don't guess you really have to worry about it.

    --ed

  5. #5
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you do not want to cache the whole page for some reason, you might want to look at my PHP DataCache project which caches PHP variables to either a file or a database so that you can just retrieve the varaible later.

    coo_t2's example might look something like:
    PHP Code:
    $CONFIG $datacache->GetCache('config'); 
    Application configuration is actually one of the areas where I tend to use DataCache. Under an MVC framework, I create an action that will set the cache (called only when setting up the application or when you make configuration changes) and otherwise use a line similar to above.

    HTH
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  6. #6
    SitePoint Member
    Join Date
    Jul 2003
    Location
    IL
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    well.. since I'm a beginner..

    Since this is my first "Big" website I never had a database be so populated before, thus I never had to use indexing.

    I indexed a lot of my tables and WOW the difference is incredible!

    Thanks for the help guys/gals


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •