简体   繁体   中英

php-cli require_once() failing on ubuntu works on mac

I am working with the voip.ms php api I wish to run a php script from the cli it works fine on my mac in terminal but on the ubuntu server it fails...

the script:

<?php
require_once("class.voipms.php");
$voipms = new VoIPms();
...

the begining of class.voipms.php

<?
class VoIPms{
...

the error

first it spits out 2000+ lines from class.voipms.php then

PHP Fatal error:  Class 'VoIPms' not found in /root/voipreg/check.php on line 3

obviously the class is in class.voipms.php and the script can find class.voipms.php because it gets printed to the cli and everything runs fine from terminal on my mac so I am rather confused!

Any help would be amazing!

PHP short tags (just <? vs the full tag <?php ) are likely disabled on the Ubuntu system. I would suggest not using short tags as they are not enabled everywhere like the full tag is. If not enabled, you will get exactly what you are describing. PHP doesn't recognize the file as code and just spits it out as text.

While you can enable the short tags in php.ini, I would suggest just not using it. You can't rely on it being enable everywhere and it's not like it is that hard to just type out the full thing. You can also still use the short echo tag <?= , even with short tags disabled, for a while now.

The class file specified is not able to be found. The way to specify the file, it is expecting it to be in either the same directory this script is being run from, or some one of the directories in you PHP include path.

Perhaps you have different include paths configured in the different environments if the class file is truly not in the same directory as this script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM