1

C で書かれた Thrift サーバー用の PHP クライアントを作成しようとしています。 http://chanian.com/2010/05/13/thrift-tutorial-a-php-client/にあるチュートリアルに従っています。

私は PHP に非常に慣れていないため、言語の基礎のいくつかが欠けていると思われます。

問題のコードは次のとおりです。

<?php 
// Setup the path to the thrift library folder
$GLOBALS['THRIFT_ROOT'] = 'Thrift';

// Load up all the thrift stuff
require_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';
require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php';

// Load the package that we autogenerated for this tutorial
require_once $GLOBALS['THRIFT_ROOT'].'/packages/encabulationgame/EncabulationGame.php';

// Several things might go wrong
try {
    // Create a thrift connection (Boiler plate)
    $socket = new TSocket('localhost', '65123'); <--error is here

「Class 'TSocket' not found in /var/www/foo/scores.php on line 22」というエラーが表示されます

TSocket は Thrift/transport/TSocket.php で定義されています。Thrift/transport/TSocket.php ファイル (コメントを削除) には次のように書かれています。

<?php

namespace Thrift\Transport;

use Thrift\Transport\TTransport;
use Thrift\Exception\TException;
use Thrift\Exception\TTransportException;
use Thrift\Factory\TStringFuncFactory;

/**
 * Sockets implementation of the TTransport interface.
 *
 * @package thrift.transport
 */
class TSocket extends TTransport {

コードを次のように変更すると:

 $socket = new Thrift\Transport\TSocket('localhost', '65123');

その後、私のコード (少なくともこの行) はエラーをスローしなくなりました。私は興味があります: このチュートリアルの作成者は、このコードを彼のシステムで動作させるために何をしましたか?私のシステムでは行っていません。

次に、次の行を追加して問題を解決しようとしました。

use Thrift\Transport;

$socket を作成する前に自分のファイルに追加しましたが、思ったほど問題は解決しませんでした。

別のファイルで定義されているこの型を PHP に解決させるにはどうすればよいですか? (解決しなければならないいくつかのファイルにいくつかのタイプがあります。)

4

1 に答える 1