I am trying to run the PEAR XMLRPC inside a plugin function to do some validation. It is all working fine in a standalone app that in a folder on my server, but as soon as I put all the files into my plugin folder, the:
require_once 'XML/RPC2/Client.php';
doesn't work. The Client.php file return an error:
Warning: require_once(XML/RPC2/Exception.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream:
So i assume it has to do with relative vs non-relative files, but I can't seem to figure out why it works outside of wordpress just fine.
If I start changing all the
require_once 'XML/RPC2...
to be the absolute path on the server the errors start going away, but I feel like I shouldn't have to change the source of PEAR and XMLRPC to do what i need. Any Suggestions?
You could update the PHP include path:
set_include_path(get_include_path() . PATH_SEPARATOR . $pathToPearLibs);
require_once($pathToPearLibs . 'XML/RPC2/Client.php');
This will give PHP one more (correct) place to look after it attempts to load from the wrong place.
Related
I have a PHP that runs fine on localhost but throws error on the cloud server. On the localhost, the script runs and also fetched the data from datastore.
This is the line thats causing the problem:
require __DIR__ . '/../../vendor/autoload.php';
// this is the line5 of datastore.php
I deploy it using this code:
gcloud app deploy --promote --stop-previous-version app.yaml
After deploying to the Google AppEngine, i get this:
Warning:
require(/base/data/home/apps/myproject/projectID/dialpad_research/api/../../vendor/autoload.php):
failed to open stream: No such file or directory in
/base/data/home/apps/myproject/projectID/dialpad_research/api/datastore.php
on line 5 Fatal error: require(): Failed opening required
'/base/data/home/apps/myproject/projectID/dialpad_research/api/../../vendor/autoload.php'
(include_path='.;/base/data/home/apps/myproject/projectID/;/base/alloc/tmpfs/dynamic_runtimes/php55_dynamic/ef537742f8701211/sdk')
in
/base/data/home/apps/myproject/projectID/dialpad_research/api/datastore.php
on line 5
This file is required inside another PHP file too.
But even if I try to access this file directly, I still get the same error.
Should I be adding the require code differently?
The problem was that the vendor folder was not getting uploaded.
.gcloudignore file was preventing it.
After correcting it, this error is gone.
Thanks everyone from trying.
Your require code should look like this. Your vendor folder should normally be at root directory level of your code on the same level as your app.yaml. In which case, your require should look like this:
require 'vendor/autoload.php';
Also, sanity check and make sure the file is actually there in the vendor folder.
I have a script that includes a file and that file has an include in it, like this:
In script:
include('includes/functions/homepage.php);
In homepage.php:
include('includes/functions/parent_functions.php');
I searched here and see it is a very common problem and the solution seems to be to use
include(dirname(__FILE__) . '/includes/functions/homepage.php');
I have the above and still get this error:
Warning: include(includes/functions/parent_functions.php): failed to open stream: No such file or directory
I've tried this on a site running php 5.5 and another using 7.2 - fails the same on both. If I print the path using the following it shows the correct full path.
echo dirname(__FILE__) . '/includes/functions/homepage.php';
As mentioned, this is a common question here but the fix isn't working in my case. Can anyone see why?
Well, you have an issue here. As the parent_functions.php and homepage.php are in the same directory you need not put an extra directory prefix. You can simply use
include('parent_functions.php');
instead of
include('includes/functions/parent_functions.php');
I've been trying to get to grips with zend framework and a bit of php and am having problems with (I think) some sort of path setting.
Basically I'm having some problems with getting a simple page to work.
I have a standard directory structure from the zend quickstart sample. It has the structure:
app
->public
->library
etc.
When I create the following "hello.php" file in the public directory, I get an error from "require-once"
Warning: require_once(/../application/Zend/Rest/Server.php) [function.require-once]: failed to open stream: No such file or directory in /home/bestpubi/public_html/svc/public/hello.php on line 2
Fatal error: require_once() [function.require]: Failed opening required '/../application/Zend/Rest/Server.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/bestpubi/public_html/svc/public/hello.php on line 2
My hello.php file looks like this:
<?php
require_once '../application/Zend/Rest/Server.php';
/**
* Say Hello
*/
function sayHello()
{
return 'finally';
}
$server = new Zend_Rest_Server();
$server->addFunction('sayHello');
$server->handle();
?>
I could really do with some help as this is driving me a bit mad, and I'm sure it's something silly.
You are requesting the required library file as follows.
require_once '../application/Zend/Rest/Server.php';
The error message indicates that, there is no such file in the path specified.
Usuallay zend framework contains it 'Zend' library inside /library directory. If you have the Zend directory in your downloaded ZendFramework files, copy it to /library directory. So that the Zend directory structure would be as follows
/library/Zend
This is a simple way to get started. Once you are familiar with the environment, try to use include path in your setting.
Try
$new_include_path = "/home/www/app/library/";
set_include_path ( get_include_path() . PATH_SEPARATOR . $new_include_path); )
to define the include path of your ZF library. Put this on the top of your page, before Including any ZF file.
Edit:
I assumed you are on linux, if you are on windows, change path accourdingly
$new_include_path = "c:\\www\\app\\library";
Looking at your website it seems the index.php from /public works fine. So I would suggest copy pasting the code that's in there to set paths for zf into hello.php and it should work.
First thing is create your files in application folder.
And If You are using Linux follow the steps,
To use Zend library you can create a short cut to zend library from your library.
From terminal go to your 'library' directory run the command
ln -s 'path to your zend library'
It will create a shortcut.
I am using windows right now but I need my script to work on windows or linux. I am working on a project which allows to upload video to youtube, the youtube library requires the use of Zend framework (unfortunately) so I am really trying to get it to work, with no luck.
So my page says
Warning: require_once(Zend/Loader.php) [function.require-once]: failed to open stream: No
such file or directory in
E:\Server\htdocs\clients\youtube2\demos\Zend\Gdata\YouTubeVideoApp\operations.php on line 37
I have Zend framework located at
E:\Server\htdocs\frameworks\Zend
I then try to set the include path so that the scripts have access to Zend, thats where my trouble starts. I try to use this...
$path = 'E:/Server/htdocs/frameworks/Zend/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
But I still get the error that you see above, now that you can see the path of my script above and the path of my Zend, can someone show me how to set the include path to work correctly? Thanks for any help
I tried some suggestions with no luck so far. Here is my updated code and result
$path = 'E:\Server\htdocs\frameworks';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
echo get_include_path();
Gives this...
E:\Server\php\PEAR;E:\Server\htdocs\frameworks
So it appears my include path for zend is added, but it still says it cannot find it
Final Update!
It is working, just where I set the include path wasn't getting included into all the files, is there a way to set the include path and have it be available globally?
If you want to change the include path in php.ini, just change include_path. Check out this tutorial to find out about a myriad of ways of changing the include path.
E:\Server\htdocs\frameworks\Zend
versus
$path = 'E:/Server/htdocs/frameworks/Zend/';
might make a difference on your system? Try it with \ instead of /.
I've been trying to install Zend Gdata. I'm running from a dev environment so have access to php.ini.
I've set the include path and when I run the verification script I get the following..
Ran PHP Installation Checker on 2011-04-28T02:25:20+00:00
PHP Extension Errors Tested
No errors found
Zend Framework Installation Errors Tested
No errors found
SSL Capabilities Errors Tested
No errors found
YouTube API Connectivity Errors Tested
No errors found
But when I try to run any of the demo files I get the floowing error...
Warning: require_once(Zend/Loader.php): failed to open stream: No such file or directory in /usr/lib/php/ZendGdata/demos/Zend/Gdata/blogger.php on line 37
Fatal error: require_once(): Failed opening required 'Zend/Loader.php' (include_path='.:/usr/lib/php') in /usr/lib/php/ZendGdata/demos/Zend/Gdata/blogger.php on line 37
The most logical conclusion is that there is a problem with the include path, but I have checked it and it seems right.
Here's what I have for it...
.:/usr/lib/php/ZendGdata/library/Zend:/usr/lib/php/ZendGdata/library/
Any suggestions would be greatly appreciated.
Put this in the beginning of Blogger.php
set_include_path('/usr/lib/php/ZendGdata/library' . PATH_SEPARATOR . get_include_path());
You say you're setting the include path in a configuration file but that doesn't seem to be affecting CLI. Make sure you're editing the right php.ini file with php --ini
$clientLibraryPath = 'ZendGdata/library';
$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $clientLibraryPath);
if you do not know the root path of the server, use relative path for accessing library. Its pretty handy to use.
above two lines should be written on the top of any file{page1,page2,page3} having folder structure as below
Website
Page1.php
Page2.php
Page3.php
ZendGdata
You can use your relative path as per your need