我使用的cronjob以下方式来触发一个PHP脚本:的cronjob需要绝对路径
/web/cgi-bin/php5 $HOME/html/library/myScript.php auth_key=xxxxxxx
但我遇到问题需要和我都试过了我能找到的stackO了。 似乎无法加载SendGrid自动加载
//myScript.php
#!/web/cgi-bin/php5
<?php
include('../config.php'); // this works well for some reason...
if(isset($_GET['auth_key']) && $_GET['auth_key'] == "xxxxxxx")
{
// send email
include('home/content/aa/bbbbbb/html/scripts/sendgrid/lib/SendGrid.php'); // this works only this way
include('home/content/aa/bbbbbb/html/scripts/unirest/lib/Unirest.php'); // this too
SendGrid::register_autoloader(); // fails here!
}
?>
而且这也没有工作,要么:
set_include_path('/home/content/aa/bbbbbb/html/');
require 'scripts/sendgrid/lib/SendGrid.php';
require 'scripts/unirest/lib/Unirest.php';
我也没有这样的:
chdir(dirname(__FILE__));
的SendGrid.php是folowwin,我认为问题出在某个地方,因为这也需要调用!
//SendGrid.php
<?php
class SendGrid {
const VERSION = "1.1.5";
protected $namespace = "SendGrid",
$username,
$password,
$web,
$smtp;
public function __construct($username, $password) {
$this->username = $username;
$this->password = $password;
}
public static function register_autoloader() {
spl_autoload_register(array('SendGrid', 'autoloader'));
}
public static function autoloader($class) {
// Check that the class starts with "SendGrid"
if ($class == 'SendGrid' || stripos($class, 'SendGrid\\') === 0) {
$file = str_replace('\\', '/', $class);
if (file_exists(dirname(__FILE__) . '/' . $file . '.php')) {
require_once(dirname(__FILE__) . '/' . $file . '.php');
}
}
}
public function __get($api) {
$name = $api;
if($this->$name != null) {
return $this->$name;
}
$api = $this->namespace . "\\" . ucwords($api);
$class_name = str_replace('\\', '/', "$api.php");
$file = __dir__ . DIRECTORY_SEPARATOR . $class_name;
if (!file_exists($file)) {
throw new Exception("Api '$class_name' not found.");
}
require_once $file;
$this->$name = new $api($this->username, $this->password);
return $this->$name;
}
}
当然,任何帮助是非常感谢! 由于提前,洛伊丝
大家好,感谢您的回复!那么我试图包括这些库,它只有当我这样做时才起作用我在我的帖子中描述 – Lois