PHP Fatal error: Uncaught Error: Class when using exec(); - php

I'm writing a web app, and I created a scraper to get data from my own site.
I have a few dependencies, so they're being extended, but now that I'm trying to run this php script from exec, and it doesn't work, I get the error:
PHP Fatal error: Uncaught Error: Class 'App\Helpers\ScraperHelper' not found in /home/username/public_html/App/Libraries/Scraper/execute.php:6.
Begin.php
This is how I'm calling my script:
exec('/usr/bin/php/ home/username/public_htm/App/Libraries/Scraper/execute.php');
Execute.php
namespace App\Libraries\Scraper;
use \App\Helpers\ScraperHelper;
$recipe = new ScraperHelper();
$recipe->fromFeed();
fromFeed() runs the script that's included in the ScraperHelper class, scrape the information from the site and inserts it into the database.
I've tried removing all the namespaces, and using require with full server path, but there are a 4 other dependencies that doesn't allow me to access them.
require_once '/home/username/public_html/App/Helpers/ScraperHelper.php';
require_once '/home/username/public_html/App/Models/Food.php';
require_once '/home/username/public_html/Core/Model.php';
Composer is autoloading two folders. Core and App, but I figure that the exec function ignores it which is why I keep getting Uncaught Error.
I believe exec isn't being able to process the namespaces and use calls, I included all the files with require_once and it worked, but It's not what I need still, I really need to know how to make exec process namespaces, use calls.

Related

Functions in Wordpress's functions.php being redeclared when called from a standalone script

I'm getting a "PHP Fatal error: Cannot redeclare function_name" error from all functions in functions.php when trying to write a standalone script.
A script with only the one line
include_once $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php';
triggers the error.
I could go through and add function_exists() conditionals to every one of the 100 or so functions, but that seems tedious on a site that works just fine otherwise.
Why would including wp-load.php from a standalone script try to redeclare these functions? What am I missing?

PHP Fatal error: Class 'Sightengine\\SightengineClient' not found in

after trying different ways of using the API from sightengine I can' get it to work, I followed the instructions on their site , installing via composer, but when I try to use it, I get the Class not found error in apache:
PHP Fatal error: Uncaught Error: Class 'Sightengine\\SightengineClient' not found in /var/www/html/photobooth/app.php
PHP file:
<?php
use Sightengine\SightengineClient;
$client = new SightengineClient('xxxxxxx', 'xxxxxxxxx');
Missed to include the file.
When installing using composer, we have to include the file in our code
require_once 'vendor'.DIRECTORY_SEPARATOR.'autoload.php';
This will help you to include the file in code, so you can start using the class/objects

S3Client gives fatal error - Fatal error: Class 'Aws\Common\Client\AbstractClient' not found

I have aws sdk in current directory. I have included sdk in file like this..
include("Aws/S3/S3Client.php");
use Aws\S3\S3Client;
class myClass{
}
It gives me fatal error like..
Fatal error: Class 'Aws\Common\Client\AbstractClient' not found in /somePath/Aws/S3/S3Client.php on line 117
Please help.
To avoid all these error while sending request or getting response from AWS, set up AWS SDK using http://aws.amazon.com/developers/getting-started/php/, or use
git clone https://github.com/awslabs/aws-php-sample.git
curl -sS https://getcomposer.org/installer | php
php composer.phar install
By installing AWS SDK in this way, you'll get a file at vendor/autoload.php
It'll take care of all the required files into the script.
I had the exact same issue and wasn't able to find an answer anywhere. So, in case anyone has the same problem in the future, for me it was simply a matter of using a version of AWS SDK that was incompatible with my PHP version.
Once I upgraded my server's PHP version it all worked fine.

undefined method Crypt_Rc4::enableContinuousBuffer()

I need to transfer some xml files via sftp to another server.
I tried to get phpseclib running for like 4 hours. Composer crashed several times trying to install phpseclib, so i downloaded it manually.
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
require('phpseclib/Net/SFTP.php');
I can't get around this error:
Fatal error: Call to undefined method Crypt_Rc4::enableContinuousBuffer() in
/Applications/XAMPP/xamppfiles/htdocs/phpseclib/Net/SSH2.php
on line 1640
I tried to track down if there are some classes which override some parent classes of Crypt_TripleDES (object on line 1640), but I did not find anything. All other classes in this project are written by me.
Edit:
Problem could be tracked down to the PHP class /Applications/XAMPP/xamppfiles/lib/php/Crypt/Rc4.php
My unsatisfying but working solution is renaming the file to _Rc4.php. But I need an another solution since I don't have too much influence on the productive server.

Fatal error cannot instantiate when trying to use http_class with http.php

Am I missing something?
I am trying to use the http.php file in my program, but I keep getting this error:
"Fatal error: Cannot instantiate non-existent class: http_class in /home/tznius/youtube/btube.php on line 84"
When I examine the http.php class itself (btube.php includes it), I don't see any declarations for the http_class and when I google it, it keep finding references to the http.php file again.
Which files, libraries, etc. am I missing
If you're using a prepackaged library, my guess is that your include path needs to be modified to include the library path. Are you getting any warning messages before the fatal error?

Categories