CMS with media content on another server

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sandman

    CMS with media content on another server

    Ok, so I'm the author of a pretty big CMS system (big as in huge, not
    market-share big) and I've been thinking about a problem for a few
    weeks here on media management.

    The CMS accomodates both images/media uploaded by admins, but also by
    members (in forum and blogs and such). Nothing strange about that at
    all.

    But now I'm faced with the need of moving - physically - all my media
    to a separate server, for distributed loads. I.e. when deploying the
    CMS you can either set localhost or media.exampel.c om as your media
    repository.

    This makes for two problems - as far as I can think of:

    1. Upload

    Upon surfing to www.example.com, and uploading an image - the image
    has to be moved to media.example.c om after it has been uploaded to the
    first server. Right? The media has to be moved first from the client,
    to the www server and then from the www server to the media server. As
    far as I can tell, there is no other way to do this. I have several
    functions to handle uploaded files, the most important one is:

    move_file($orig inal_path, $to_dir);

    And to handle this, this function has to know when media server isn't
    "localhost" and facilitate the transfer to the other server, maybe by
    a second POST to media.example.c om?


    2. <imgtags

    The next problem is when the PHP script should output an image that is
    physically located on another machine. Today, I use imagemagick to
    convert it to the wanted size and geometry and saves it in a cache
    directory and then outputs a <imgtag that points to this directory.

    With the file on another server, the PHP script on the www server can
    only output something along the lines of:

    <img src='http://media.example.c om/img.php?path=/path/to/file.jpg'>

    For example. And img.php on media.example.c om will do all the
    conversions needed (in accordance to whatever size or geometry
    specifications sent along in the IMG tag).

    But, this isn't valid HTML. the <imgtag should always contain
    width/height parameters or it will not validate. Not that my code
    validates perfectly anyway, but I rather have this information since
    it speeds up parsing by the browser as well.

    Is there anyone out there that has done something like this before and
    knows a good way to get something that isn't half-bad?

    --
    Sandman[.net]
  • OmegaJunior

    #2
    Re: CMS with media content on another server

    On Mon, 26 Feb 2007 16:10:54 +0100, Sandman <mr@sandman.net wrote:
    Ok, so I'm the author of a pretty big CMS system (big as in huge, not
    market-share big) and I've been thinking about a problem for a few
    weeks here on media management.
    >
    The CMS accomodates both images/media uploaded by admins, but also by
    members (in forum and blogs and such). Nothing strange about that at
    all.
    >
    But now I'm faced with the need of moving - physically - all my media
    to a separate server, for distributed loads. I.e. when deploying the
    CMS you can either set localhost or media.exampel.c om as your media
    repository.
    >
    This makes for two problems - as far as I can think of:
    >
    1. Upload
    >
    Upon surfing to www.example.com, and uploading an image - the image
    has to be moved to media.example.c om after it has been uploaded to the
    first server. Right? The media has to be moved first from the client,
    to the www server and then from the www server to the media server. As
    far as I can tell, there is no other way to do this. I have several
    functions to handle uploaded files, the most important one is:
    >
    move_file($orig inal_path, $to_dir);
    >
    And to handle this, this function has to know when media server isn't
    "localhost" and facilitate the transfer to the other server, maybe by
    a second POST to media.example.c om?
    >
    Have you thought of setting up a synchronisation mechanism? You could code
    a directory watcher that periodically looks for changes in a directory and
    then copies those changes to the remote system. You could do that
    directly, but you could also use a synchronisation command catcher on the
    remote system, that reacts for instance to SOAP XML requests and then
    performs the commands locally. That way you can implement a security
    mechanism to prevent abuse.
    >
    2. <imgtags
    >
    The next problem is when the PHP script should output an image that is
    physically located on another machine. Today, I use imagemagick to
    convert it to the wanted size and geometry and saves it in a cache
    directory and then outputs a <imgtag that points to this directory.
    >
    With the file on another server, the PHP script on the www server can
    only output something along the lines of:
    >
    <img src='http://media.example.c om/img.php?path=/path/to/file.jpg'>
    >
    For example. And img.php on media.example.c om will do all the
    conversions needed (in accordance to whatever size or geometry
    specifications sent along in the IMG tag).
    >
    But, this isn't valid HTML. the <imgtag should always contain
    width/height parameters or it will not validate. Not that my code
    validates perfectly anyway, but I rather have this information since
    it speeds up parsing by the browser as well.
    >
    Is there anyone out there that has done something like this before and
    knows a good way to get something that isn't half-bad?
    >
    Height and width are implied for html 4.01, meaning you can omit them
    safely, and still have the document validate. The image element will then
    be displayed at the size of its source, unless you control it using CSS,
    for instance.

    --
    Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

    Comment

    • Sandman

      #3
      Re: CMS with media content on another server

      In article <op.todpa6n970m clq@cp139795-a.landg1.lb.hom e.nl>,
      OmegaJunior <omegajunior@sp amremove.home.n lwrote:
      1. Upload

      Upon surfing to www.example.com, and uploading an image - the image
      has to be moved to media.example.c om after it has been uploaded to the
      first server. Right? The media has to be moved first from the client,
      to the www server and then from the www server to the media server. As
      far as I can tell, there is no other way to do this. I have several
      functions to handle uploaded files, the most important one is:

      move_file($orig inal_path, $to_dir);

      And to handle this, this function has to know when media server isn't
      "localhost" and facilitate the transfer to the other server, maybe by
      a second POST to media.example.c om?
      >
      Have you thought of setting up a synchronisation mechanism? You could code
      a directory watcher that periodically looks for changes in a directory and
      then copies those changes to the remote system. You could do that
      directly, but you could also use a synchronisation command catcher on the
      remote system, that reacts for instance to SOAP XML requests and then
      performs the commands locally. That way you can implement a security
      mechanism to prevent abuse.
      Well - the media shouldn't be kept on server1. It should have no media
      files. All should be on server2. So files uploaded to server1 should
      automatically be forwarded to server2 instantly and then be erased on
      server1.
      2. <imgtags

      The next problem is when the PHP script should output an image that is
      physically located on another machine. Today, I use imagemagick to
      convert it to the wanted size and geometry and saves it in a cache
      directory and then outputs a <imgtag that points to this directory.

      With the file on another server, the PHP script on the www server can
      only output something along the lines of:

      <img src='http://media.example.c om/img.php?path=/path/to/file.jpg'>

      For example. And img.php on media.example.c om will do all the
      conversions needed (in accordance to whatever size or geometry
      specifications sent along in the IMG tag).

      But, this isn't valid HTML. the <imgtag should always contain
      width/height parameters or it will not validate. Not that my code
      validates perfectly anyway, but I rather have this information since
      it speeds up parsing by the browser as well.

      Is there anyone out there that has done something like this before and
      knows a good way to get something that isn't half-bad?
      >
      Height and width are implied for html 4.01, meaning you can omit them
      safely, and still have the document validate. The image element will then
      be displayed at the size of its source, unless you control it using CSS,
      for instance.
      Yeah, but it speeds up the browser to not have to wait for the image
      data before positioning it on the canvas.

      Either way, I've gotten this far:

      1. Client connects to index.php on server1
      2. index.php uses function img()
      3. img() takes a image path from the database
      4. img() sends a HTTP request to server2/img.php
      5. img.php resizes original image at given path
      6. img.php caches resized image on server2
      7. img.php responds with "width height path-to-cache"
      8. img() outputs a <imgtag with above properties
      9. client connects to server2 to fetch the image

      This way, only two PHP requests has been made, and one file request.





      --
      Sandman[.net]

      Comment

      Working...