我寫了一個解決方案,PHP應用解決主要是兩種類型的問題:
- 如何共享數據/ PHP程序之間的變量,在相同/型動物服務器
- 託管如何同步在數據讀/寫操作/變量
我的項目是在GitHub上ANYEM Project
託管210
第一:使用命令行啓動ANYEM_SERVER現在
php ANYEM/ANYEM_SERVER/anyem.app.server.impl/ServerImpl.php
,在你的PHP應用程序,你可以做如下:
<?php
// load server's connection configuration (ANYEM_SERVER IP and Port Number ...)
$clientConnection = ClientConnectionImpl::newClient();
// build a key for your variable that will be stored in server
// the key is composed on 3 Parts : [1] => URL, [2] => Variable Namespace, [3] => Variable Name
$identifier = new ResourceIdentifierImpl("anyem.com", "anyemNameSpace", "a");
$a = 5;
$anyemClient = new AnyemClientImpl($clientConnection, $identifier);
try {
// if $a is reserved by another PHP Process, so this process
// will sleep (1/10) seconds and retry the reservation of the resource
// here, the max number of reservation attempts is 5, if reservation
// fails, an Exception will be thrown
$responseWrapper = $anyemClient->get($a, 5, 100000);
// here we have reserved the variable $a, and we have the unserialized contents
$a = $responseWrapper->getResource()->getData();
// here, we update the contents, send it to ANYEM_SERVER and releasing the lock (we unreserve it)
$anyemClient->put(++$a);
}
catch (Exception $e) {
print $e->getMessage() . "\n";
continue;
}
希望可以幫助別人:)
@Ihsan這個例子實際上應該說明這個想法;) – helle