確保您已安裝PHP CLI軟件包。在我的Ubuntu VPS我不得不跑:
$ apt-get install php5-cli
檢查它的安裝:
$ /usr/bin/php -v
然後,創建一個名爲像sendsms.php
與內容類似於此文件:
#!/usr/bin/php -q
<?php
// command line parameters are in the format:
// key1 value1 .. keyN valueN number message
$username = "";
$password = "";
$apikey = "";
// process pairs of arguments up to the last two
for ($x = 0; $x < ($argc - 3); $x++)
{
if ($argv[$x] == "-u") $username = $argv[$x + 1];
if ($argv[$x] == "-p") $password = $argv[$x + 1];
if ($argv[$x] == "-k") $apikey = $argv[$x + 1];
}
$number = $argv[$argc - 2];
$message = $argv[$argc - 1];
// To do: call the SMS API
// For now just output the info
echo("Username = " . $username . "\r\n");
echo("Password = " . $password . "\r\n");
echo("API key = " . $apikey . "\r\n");
echo("Number = " . $number . "\r\n");
echo("Message = " . $message . "\r\n");
?>
確保該文件具有執行權限:
chmod 755 sendsms.php
然後從當前文件夾像這樣運行:
$ ./sendsms.php -u your_username -p your_password -k your_api_key 447771234567 'Hello from CLI'
我想你會更好地提供更多的約束條件:可以把班級從例如訪問C,從一個shell,從Ruby,... – xtofl 2009-06-27 10:21:54