PHP set_include_path and require_once - php

I have an error that happens only on my host server, on my local environment not:
Fatal error: require_once() [function.require]: Failed opening required '\Audero\Loader\AutoLoader.php' (include_path='.:/usr/share/pear:/usr/share/php:/home/httpd/vhosts/webox-it.com/ofrom.webox-it.com/modules/Concordancier....\lib') in /home/httpd/vhosts/webox-it.com/ofrom.webox-it.com/modules/Concordancier/data_manager.php on line 1670
Here is my code:
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . '/../../lib/');
require_once 'Audero\Loader\AutoLoader.php';
spl_autoload_register('Audero\Loader\AutoLoader::autoload');
// Extract the chunk and save it on the hard disk
try {
$extractor = new \Audero\WavExtractor\AuderoWavExtractor($inputFile);
$extractor->saveChunk($start, $end, $outputFile);
...
Files structure:
/lib/Audero/Loader/Autoloader.php
Calling file emplacement:
/modules/Concordancier/data_manager.php
In my local environment there's no problem, php can load the autoloader, but in the prod server it does not.
The source files structure is exactly the same as the local one, and the relative path looks correct. The php version in prod is 5.3.27 so it should work ?
Any idea ?

Related

Cannot require parent directory in phpUnit

I have a problem with phpUnit.
Whenever I try to open a file using require (or any other similar function) which is not in the same directory or subdirectory as the test file itself, phpUnit throws this error:
Warning: include_once Failed opening "C:\....." for inclusion (include path = '.;C:\xampp\php\PEAR')
Can anybody tell me what I am doing wrong? Thank you
try using realpath and dirname to get a full path
# ../myfolder/file.php
$path = realpath(dirname(dirname(__FILE__)))."/myfolder/file.php"
# ./file.php
$path = realpath(dirname(__FILE__))."/file.php"
# ../file.php
$path = realpath(dirname(dirname(__FILE__)))."/file.php"
# ../../file.php
$path = realpath(dirname(dirname(dirname(__FILE__))))."/file.php"

Can't Parse Up One Directory Command in PHPUnit Testing with PHPStorm

I have PHPUnit set up in my PHPStorm project. I've referenced the PHPUnit phar file and have a PHP executable linked to my PHPStorm run configuration. My directory structure looks like:
/lib/classes/Class.php
/lib/vendor/phpunit.phar
/lib/test/ClassTest.php
In my ClassTest.php file, I reference the other two files with:
require_once (__DIR__ . "../vendor/phpunit.phar");
require_once (__DIR__ . "../classes/Class.php");
I get the following error when I run my test:
Fatal error: require_once(): Failed opening required
'C:\Users\me\PhpstormProjects\myproject\lib\tests../vendor/phpunit.phar'
It seems like the PHP parser isn't correctly parsing the up one directory ../ command.
Why is this happening?
First of all: this line is not needed (at all) as PHPUnit will already be loaded at that time.
require_once (__DIR__ . "../vendor/phpunit.phar");
Secondly: __DIR__ constant in PHP does not contain trailing slash. When used in require/include statements (and other places when building full file path) you have to add it yourself.
In your particular case it has to be (note / before ..):
require_once (__DIR__ . "/../classes/Class.php");

Start Solarium Client

I have problem with start Solarium Client, I downloaded it by Composer and GitHub according the wiki tutorial, it's ok, but I don't know what I must do now.
When I tried this example code:
<?php
require(__DIR__.'/init.php');
htmlHeader();
// check solarium version available
echo 'Solarium library version: ' . Solarium\Client::VERSION . ' - ';
// create a client instance
$client = new Solarium\Client($config);
// create a ping query
$ping = $client->createPing();
// execute the ping query
try {
$result = $client->ping($ping);
echo 'Ping query successful';
echo '<br/><pre>';
var_dump($result->getData());
echo '</pre>';
} catch (Solarium\Exception $e) {
echo 'Ping query failed';
}
htmlFooter();
I have the following error:
Warning: require(C:\xampp\htdocs\solarium/init.php): failed to open stream: No such file or directory in C:\xampp\htdocs\solarium\test.php on line 3
Fatal error: require(): Failed opening required 'C:\xampp\htdocs\solarium/init.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\solarium\test.php on line 3
I use Xampp server.
Must I set some Path, where appropriate, how and where? File init.php is in folder: C:\xampp\htdocs\solarium\vendor\solarium\solarium\examples\ and i start the demo file in folder: C:\xampp\htdocs\solarium\
Sorry for my English. Thank you for help.
You have to run solarium examples, and examples derived form them like your test.php file, from the /examples directory in the solarium directory tree.
In this directory there is init.php file which is setting up 'display_errors' init variable, loading composer created autoload.php, loading the config.php and defining htmlHeader() and htmlFooter() functions.

PHP include with ../ failed open

I am trying to include a php file from the parent directory and I getting error:
admin#webby:~$ /usr/bin/php
/var/phpscripts/email_parser/tests/_email-test.php PHP Fatal error:
require_once(): Failed opening required '../PlancakeEmailParser.php'
(include_path='.:/usr/share/php:/usr/share/pear') in
/var/phpscripts/email_parser/tests/_email-test.php on line 6
Fatal error: require_once(): Failed opening required
'../PlancakeEmailParser.php'
(include_path='.:/usr/share/php:/usr/share/pear') in
/var/phpscripts/email_parser/tests/_email-test.php on line 6
PHP file
#!/usr/bin/php
<?php
error_reporting(E_ALL ^ E_NOTICE ^E_WARNING);
ini_set("display_errors" , 1);
require_once("../PlancakeEmailParser.php");
// etc
?>
Folder Structure
admin#webby:/var/phpscripts/email_parser$ find .
.
./composer.json
./README.txt
./LICENSE.txt
./PlancakeEmailParser.php
./tests
./tests/_email-test.php
For testing it works fine when I move PlancakeEmailParser.php into the tests directory and remove the "../" from the require
The line
require_once("../PlancakeEmailParser.php");
Is not using a fully qualified file-system path or PHP-URI-scheme. Therefore its outcome depends on PHP configuration, most often because of the include directory configuration.
The PHP CLI can use a different configuration file than with your webserver - or - the working directory is different as with your webserver (probably the later plays more of a role in your specific scenario).
What you want can be easily expressed fully qualified, too:
require_once(__DIR__ . "/../PlancakeEmailParser.php");
This is probably what you're looking for.
Quote from PHP CLI SAPI: Differences to other SAPIs:
It does not change the working directory to that of the script. (-C
and --no-chdir switches kept for compatibility)
In order to keep relative paths in your script working as-is, change directory to where the script resides, then execute the script:
cd /var/phpscripts/email_parser/tests/ && ./_email-test.php

Netbeans: How to configure a remote server's PHPUnit path?

I use the latest version of Netbeans on Windows, and connect to a remote Ubuntu Apache server to a Zend Framework project. I installed on that server PHPUnit, but I didn't know what is the absolute path to the phpunit.bat (I need th absolute path in NetBeans Option->Php->Unit Testing). I installed XAMPP on my computer and tried to use PHPUnit within XAMPP and the project from the remote server, but I have problems with the include paths, for example I get this error:
'Warning: include_once(PHP\Invoker.php): failed to open stream: No
such file or directory in Y:\mos\public_html\library\Zend\Loader.php
on line 146'.
Here is my bootstrap.php file:
<?php
error_reporting( E_ALL | E_STRICT );
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
define('APPLICATION_PATH', realpath('Y:/mos/public_html' . '/application'));
define('APPLICATION_ENV', 'development');
define('LIBRARY_PATH', realpath('Y:/mos/public_html' . '/library'));
define('TESTS_PATH', realpath(dirname(__FILE__)));
$_SERVER['SERVER_NAME'] = 'http://mos.loc';
$includePaths = array(LIBRARY_PATH, get_include_path());
set_include_path(implode(PATH_SEPARATOR, $includePaths));
require_once "Zend/Loader/Autoloader.php";
$loader = Zend_Loader_Autoloader::getInstance();
$loader->setFallbackAutoloader(true);
$loader->suppressNotFoundWarnings(false);
Zend_Session::$_unitTestEnabled = true;
Zend_Session::start();
?>
Can I set somehow the absolute path to the PHPUnit on the remote server from Netbeans, or can I make it work using the project from the remote server, and PHPUnit from my XAMPP?
Perhaps your mapped network drive isn't mapped under whatever account is running the web server.
Under your own account, check what the mapping is for your Y drive:
C:\>net use
The output should be something like this:
New connections will not be remembered.
Status Local Remote Network
-------------------------------------------------------------------------------
OK Y: \\server\share Microsoft Windows Network
Then modify your PHP script to attempt to map the drive for your scripting purposes:
<?php system("net use Y: \\server\share password /user:username /persistent:no >nul 2>&1"); ?>

Categories