Archived

This forum has been archived. Please start a new discussion on GitHub.

Developing a FileSystem Client in PHP

I don't understand why this topic is missing in your otherwise fairly extensive documentation?!?!

I'm not a PHP programmer but I need to evaluate ICE to implement an interface accross processor boundaries between a C++ server and Python/PHP clients.

I wonder if you have a PHP sample implementation of the basic FileSystem client resembling the functionality implemented in C++ and explained chapter 7?

Comments

  • mes
    mes California
    Please see this thread for information on our forum support policy:

    http://www.zeroc.com/vbulletin/showthread.php?t=1697
  • Do you like this better?
  • Attached is a smal sample that I wrote but at present I get the error:

    Fatal error: listRecursive(): unknown operation in c:\oracle\ora91\Apache\Apache\htdocs\filesystemclient.php on line 41

    I can't see what is wrong.
  • mes
    mes California
    Thanks Peter.

    We don't have a good reason for omitting the filesystem example in PHP. We'll add this to the manual.

    Here is the PHP code for the client:
    <?php
    Ice_loadProfile();
    
    // Recursively print the contents of directory "dir"
    // in tree fashion. For files, show the contents of
    // each file. The "depth" parameter is the current
    // nesting level (for indentation).
    
    function listRecursive($dir, $depth = 0)
    {
        $indent = str_repeat("\t", ++$depth);
    
        $contents = $dir->_list(); // list is a reserved word in PHP
    
        foreach ($contents as $i) {
            $dir = $i->ice_checkedCast("::Filesystem::Directory");
            $file = $i->ice_uncheckedCast("::Filesystem::File");
            echo $indent . $i->name() .
                ($dir ? " (directory):" : " (file):") . "\n";
            if ($dir) {
                listRecursive($dir, $depth);
            } else {
                $text = $file->read();
                foreach ($text as $j)
                    echo $indent . "\t" . $j . "\n";
            }
        }
    }
    
    try
    {
        // Create a proxy for the root directory
        //
        $base = $ICE->stringToProxy("RootDir:default -p 10000");
    
        // Down-cast the proxy to a Directory proxy
        //
        $rootDir = $base->ice_checkedCast("::Filesystem::Directory");
    
        // Recursively list the contents of the root directory
        //
        echo "Contents of root directory:\n";
        listRecursive($rootDir);
    }
    catch(Ice_LocalException $ex)
    {
        print_r($ex);
    }
    ?>
    
    Take care,
    - Mark
  • mes
    mes California
    PeteH wrote:
    Attached is a smal sample that I wrote but at present I get the error:

    Fatal error: listRecursive(): unknown operation in c:\oracle\ora91\Apache\Apache\htdocs\filesystemclient.php on line 41

    I can't see what is wrong.
    You need to change $objDir->list() to $objDir->_list(). Since "list" is a reserved word in PHP, the Slice mapping prepends an underscore to its name. You can find a list of PHP's reserved words here:

    http://www.php.net/manual/en/reserved.php

    Take care,
    - Mark
  • That's it - my page works now. Thanks for your help.