Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How many people use PHP.NET?
Old 06-24-2008, 02:37 PM How many people use PHP.NET?
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
I'm curious how many people take advantage of the power of the .NET Framework in PHP? Interestingly, you can use Ruby, Python and PHP together on the same project. In other words, if you're doing the user interface while somebody else writes the logging, instrumentation, and database access code, both of you can work in your preferred language. You can call functions written in Ruby from PHP, etc.

But that's more of a toy capability. I wonder who's using PHP.NET for the superior cacheability? Being able to scope variables at the application level, instead of the session level, is tremendous. You can cache the 100 items in a drop down list so you don't have to issue so many round trips to the database, but you only need to store 1 copy, instead of 1 per user! Then there's the magic of weak references, cache dependancy, etc.

Then there's threading. Need to log information about a page request? Why make your user wait for it to be written! Do this on a background thread, or, better yet, send it to the ThreadPool - fire and forget. Or, if you need a file to be read in, in order to make a page, queue the IO as the first step, force it to run on another CPU core (by affinity), and then it will be ready by the time you're ready to deal with it. Then there's LINQ and PLINQ for data access, and Inline XML.

So, how many people are leveraging these advances to the PHP language?
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-24-2008, 05:02 PM Re: How many people use PHP.NET?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Not me. Is there a non-Microsoft alternative? I already have my own caching class, but the threading is what intrigues me.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 06-24-2008, 07:55 PM Re: How many people use PHP.NET?
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Project Mono will run any .NET code except platform invoke. You can run C# code if your server allows. And you can still take advantage of compiled code, instead of interpreting it.

Threading can be hugely beneficial. I can talk more about threading strategies, but I don't know about alternatives to PHP.NET that will accomplish this. Tripy wrote a post a while ago on his blog, talking about a 3rd party threading framework that I believe you can attach to the PHP engine.

How does your caching framework work? Do you do aging? That can be done with .NET, and fairly easily, but it's very often not. I've found an aged cache to be more than an order of magnitude better in terms of performance than a system where everything has an equal priority. How do you store things, tho? I ask because keeping much used data in memory is helpful for obvious reasons, but I'm not aware of how to keep only 1 copy of that data, when it's functionally scoped as such? An application vs a session store?

I think Python supports fibres, right? These are conceptually similar to threads, but far more scalable in most cases. I don't know whether you can do your own reentrancy with them?
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-24-2008, 08:02 PM Re: How many people use PHP.NET?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
I'll check out Tripy's blog after I move (moving this weekend and won't be around much next week).

Yes, I do cache based on time, if necessary. Otherwise, it keeps a permanent cache which is then updated when the content changes. I plan on extending it a bit based on some techniques I've learned, but here's the PHP 5 class I currently use (feedback always welcome).

PHP Code:
<?php
/**
 * Web 2.0 Cart CacheControl Class
 *
 * Control of $_GET['page'] is done through resources/cache-control/cache-control.php
 *
 * For specific cache control, use this code:
//Fetch cache if it exists or else create it.
if (($cached_page = CacheControl::retrieveCache('MY_UNIQUE_ID_CODE')) !== false) {
  // echo $cached_page;
  // or
  // $this->template_body = $cached_page;
} else {
  //Output if necessary
  // echo $non_cached_page;
  // or
  // $this->template_body = $non_cached_page;
  CacheControl::updateCache('MY_UNIQUE_ID_CODE',$non_cached_page);
}

//Fetch cache if it exists and is less than STORAGE_LENGTH hours old or else create/update it.
if (($cached_page = CacheControl::retrieveCache('MY_UNIQUE_ID_CODE')) !== false && CacheControl::cacheFileAge('MY_UNIQUE_ID_CODE') < STORAGE_LENGTH*60*60) {
  // echo $cached_page;
  // or
  // $this->template_body = $cached_page;
} else {
  //Output if necessary
  // echo $non_cached_page;
  // or
  // $this->template_body = $non_cached_page;
  cacheControl::updateCache('MY_UNIQUE_ID_CODE',$non_cached_page);
}

 *
 * @author     Jeremy Miller
 * @copyright  2007-2008 TeraTask Technologies, LLC
 */

class CacheControl {
  private 
$cached_pages = array();

  public function 
notifications($notification_point) {
    global 
$website;
    
//Called for each notification point where a listener is added
    
if ($notification_point == Web20Cart::PRE_CREATE_BODY) {
      if (isset(
$this->cached_pages[$website->page])) {
        
//Fetch cache if the cache is younger than $this->cached_pages[$website->page] hours old.
        
if (($cached_content CacheControl::retrieveCache('index', (int)@filemtime($website->file_base.'files/cache/'.sha1($this->cached_pages[$website->page]['file_name']).'.txt') < mktime() - $this->cached_pages[$website->page]['storage_length']*60*60)) !== false) {
          
$website->template_body $cached_content;
          
$website->page 'cached_page'//Value of "cached_page" is NOT used, so the content will not be included.
        
}
      }
    } else if (
$notification_point == Web20Cart::POST_CREATE_BODY) {
      if (isset(
$this->cached_pages[$website->page])) {
        
//Updates cache every $this->cached_pages[$website->page] hours.
        //Does not affect template cache.
        
cacheControl::UpdateCache('index'$website->template_body, (int)@filemtime($website->file_base.'files/cache/'.sha1($this->cached_pages[$website->page]['file_name']).'.txt') < mktime() - $this->cached_pages[$website->page]['storage_length']*60*60);
      }
    }
  }
  public function 
addCachedPage($page_id$max_age_hours$page_file null) {
    if (
$page_file == null) {
      
$page_file $page_id;
    }
    
$this->cached_pages[$page_id] = array("file_name"=>$page_file"storage_length"=>(float)$max_age_hours);
  }
  public static function 
updateCache($file_id$content$page_condition true) {
    if (
$page_condition) {
      try {
        
$file_store = new FileStore(''sha1($file_id).".txt"'cache');
        
$file_store->write($content);
        return 
true;
      } catch (
Exception $e) {
        return 
false;
      }
    } else {
      return 
false;
    }
  }
  public static function 
cacheFileAge($file_id) {
    if (
file_exists($website->file_base.'files/cache/'.sha1($file_id).'.txt')) {
      return 
mktime() - (int)@filemtime($website->file_base.'files/cache/'.sha1($file_id).'.txt');
    } else {
      return 
0;
    }
  }
  public static function 
retrieveCache($file_id$page_condition true) {
    global 
$website;
    if (
$page_condition) {
      
//Want to return true;
      
if (file_exists($website->file_base.'files/cache/'.sha1($file_id).'.txt') && !is_dir($website->file_base.'files/cache/'.sha1($file_id).'.txt')) {
        try {
          
$file_store = new FileStore(''sha1($file_id).".txt"'cache');
          
$file_store->load();
          return 
$file_store->string;
        } catch (
Exception $e) {
          return 
false;
        }
      } else {
        return 
false;
      }
    } else {
      return 
false;
    }
  }
}
?>
I use that code in an overall core I have created which I call Web 2.0 Cart, hence it's peppering throughout.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 06-25-2008, 02:46 PM Re: How many people use PHP.NET?
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Quote:
Originally Posted by JeremyMiller View Post
Yes, I do cache based on time, if necessary. Otherwise, it keeps a permanent cache which is then updated when the content changes. I plan on extending it a bit based on some techniques I've learned, but here's the PHP 5 class I currently use (feedback always welcome).
Age and time are different things, similar as they might sound. In an aged cache system, all items in the cache are aged periodically. On the other hand, cache hits "rejuvenate" them, make them younger. When the host comes under memory pressure, or at some threshold (if you'd like to be proactive) older items die of natural causes. This way, as the system works, the more important items will gain priority in the cache. That could be the oldest, newest, or anywhere in the middle.

It looks like your caching class uses the file system instead of RAM as a backing store?
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-25-2008, 02:51 PM Re: How many people use PHP.NET?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Yeah, it uses files. That's because I work on shared hosts, so I can't play with the memory. I then setup conditionals to re-do the work and update the cache if it's older than a desired amount. For example, my RSS feeds -- cached for 24 hours. This significantly helps reduce server load when people setup their feed readers to check every 5 minutes.

I don't have any memory-based caching code written.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 06-25-2008, 05:47 PM Re: How many people use PHP.NET?
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Oh. I see. You know, all of that stuff is already done for you if you use PHP.NET - or any .NET language. You don't have to write a single line of code - just set some properties, like a boolean for whether the web server should cache the output of a given page, and some optional ones like the duration and such. Then there's a 1 line InvalidateCache() method you can call if need be.

I don't mean to offend with this next bit, but that's really among the simplest cache levels that come out of the box. I get the sense someone of your intelligence and work ethic could achieve a great deal with a proper set of tools, so you can work on implementing what you want to write, instead of on its plumbing.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-25-2008, 05:56 PM Re: How many people use PHP.NET?
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
No offense LearningNewbie. As I say all the time, I'm always looking to make my skills better. I will be looking at this in greater detail after I get done with my move (won't be available at all next week). I also need to check the availability of the technology on shared hosts as I do work for a lot of people who are on shared hosts.

I know that PHP also has a cache class and can't remember why I rejected it when I first looked at it. It may be more intelligent than my own routine.

Thank you very much for the advice and suggestions.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 06-25-2008, 06:09 PM Re: How many people use PHP.NET?
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
No problem, and feel free to send questions my way. I don't know terribly much about the PHP implementation, but I've been doing .NET and general software development for a very long time, and I'm always glad to share what I've learned along the way.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-25-2008, 06:52 PM Re: How many people use PHP.NET?
RabidSniper's Avatar
Skilled Talker

Posts: 57
Name: Jesse
Location: Phoenix, AZ
Trades: 0
You can scope variables at the application level in any .NET application..

Its called using the STATIC keyword.. Or you can store object collections in the Application class.

Also.. Application wide cache is readily available in the System.Web.Caching namespace.. you can cache really any object you want.. but its completely App domain wide in its scope..

heres an example of helper functions to set and get DataSet objects from Cache.

Code:
   #region Cache DataSet Object into HTTP Context
    public static bool CacheData(DataSet oDS, string LABEL)
    {
        bool bReturn = false;
        try
        {
            if (IsCacheEnabled)
            {
                if (LABEL.Trim() != "")
                {
                    HttpContext.Current.Cache.Insert(LABEL.Trim().ToUpper(), oDS);
                    bReturn = true;
                }
            }
        }
        catch (Exception e)
        {
            ErrorLogger.Log(e);
        }
        return bReturn;
    } 
    #endregion
 
 
 
   #region Get DataSet Object from HTTP Context Cache
    public static DataSet GetDataSetFromCache(string LABEL)
    {
        DataSet oDS = null;
        try
        {
            if (IsCacheEnabled)
            {
                if (HttpContext.Current.Cache[LABEL.Trim().ToUpper()] != null)
                {
                    oDS = HttpContext.Current.Cache[LABEL.Trim().ToUpper()] as DataSet;
                }
            }
        }
        catch { }
        return oDS;
    } 
    #endregion
PHP is neat, and its great thats available to the Framework now using the DLR (right?) but I wouldnt call it superior.
RabidSniper is offline
Reply With Quote
View Public Profile
 
Old 06-25-2008, 07:01 PM Re: How many people use PHP.NET?
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
I think you're misreading what I'd written - that or I miswrote it! It's true you can use static to make an object act a lot like a singleton, but you can also store an object (or lack thereof, a null pointer) in either the session store, or application store, under .NET.

When I said "I wonder who's using PHP.NET for the superior cacheability?" what I meant was to take a census of PHP users who've moved to an execution framework that offers superior caching. Which .NET clearly does. In the past, language has been a clear barrier, but that's no longer the case.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-25-2008, 07:05 PM Re: How many people use PHP.NET?
RabidSniper's Avatar
Skilled Talker

Posts: 57
Name: Jesse
Location: Phoenix, AZ
Trades: 0
Quote:
Originally Posted by Learning Newbie View Post
I think you're misreading what I'd written - that or I miswrote it! It's true you can use static to make an object act a lot like a singleton, but you can also store an object (or lack thereof, a null pointer) in either the session store, or application store, under .NET.

When I said "I wonder who's using PHP.NET for the superior cacheability?" what I meant was to take a census of PHP users who've moved to an execution framework that offers superior caching. Which .NET clearly does. In the past, language has been a clear barrier, but that's no longer the case.

Ahh I see... Yes I read it differently... and I think you are right.. PHP users will find the values of the framework to be very helpful.. You see that already a lot with IronPython and IronRuby too.. (like you pretty much mentioned..) lol sorry didnt mean to hijack the thread with c# stuff..
RabidSniper is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How many people use PHP.NET?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.46433 seconds with 12 queries