Weird issue launching yii script - php

I am getting a weird issue with a yii2 application (based in yii2-app-advanced) in the server, the thing is that the app frontend and backend are running ok, but the console tool (the yii script) is not working and is not throwing any errors.
Doing some debug by printing I have been able to track the issue to the requires calls in this block of code inside the script:
$config = yii\helpers\ArrayHelper::merge(
require __DIR__ . '/common/config/main.php',
require __DIR__ . '/common/config/main-local.php',
require __DIR__ . '/console/config/main.php',
require __DIR__ . '/console/config/main-local.php'
);
But I have no idea why the requires calls are failing without throw any errors. The config paths are ok and the files has no syntax errors (my local copy with same php and mysql versions works ok)
I have other yii2 apps in the server and they are working just ok.
Any tip will be really helpful because this thing is driving me crazy...

Seems that was a corrupted file in the project or composer, I Have cloned the project again, cleaned the composer cache, and installed the vendors, and now is working ok.

Related

Sentry: How to configure sentry in php?

This is for Sentry (Open-source error tracking) users.
I have tried some code, but I don't get success. I hope you could look into this.
Thanks to everyone in advance.
I have download the SDK zip and upload it on servers. Well, I have read from some stuff for autoloader and raven_client but still, I don't find autoloder.php.
I am using sentry/sdk:2.0.3
require_once 'sentry-php-master/src/Sdk.php';
Sentry\init(['dsn' => '___DSN___' ]);
throw new Exception("My first Sentry error!");
I am expecting it works and I can trace the errors.
Why aren't you using composer ?
Composer solves a number of problems including dependency resolution for PHP packages, keeping all packages updated and another benefit of using composer is autoloading.
I would suggest the following approach:
composer require sentry/sdk:2.1.0 in your project's root directory.
require_once __DIR__ . '/vendor/autoload.php';
Connect the SDK to Sentry
Sentry\init(['dsn' =>
'https://6cxxx20aa1xxx5axx47xxxb8#sentry.io/18xxx47']);
Lastly, verify your setup by triggering a PHP exception by throwing one as you've already done with throw new Exception("My first Sentry error!");
Docs

Google GCP error with tutorial code

Resolving the issue. My Case:
Before reading the question, my issue was solved due to my development environment. Using CodeKit (an application on MacOS), upon building my code from the source folder, items such as the composer.json and other files did not transfer causing the issues described below. If this does happen to you scout the two folder to look for discrepancies the paste the missing docs from the src to the build folder.
:: QUESTION ::
I am starting to use GCP today and after following the instructions defined here:
composer require google/cloud-storage
then:
putenv("GOOGLE_APPLICATION_CREDENTIALS=/path/to/creds.json");
require __DIR__.'/vendor/autoload.php';
use Google\Cloud\Storage\StorageClient;
$myid = "my-project-id";
$storage = new StorageClient([
'projectId'=>$myid
]);
var_dump($storage->buckets());
When running this i get the following error:
Fatal error: Class 'Google\Auth\Cache\MemoryCacheItemPool' not found in /place/to/vendor/google/cloud-core/RequestWrapperTrait.php on line 94
I have no idea how to solve the issue, as i am just getting started with GCP. No idea whether this is a problem with the platform or my code.
File structure appears as follows for the Google Auth:
vendor
google
auth
src
tests
cloud-core
cloud-storage
the /Cache/MemoryCacheItemPool exists inside both the tests and src folder, but the above is referencing it minus the src or tests folder.
I have also ran:
composer update
and uninstalled and reinstalled the package to no effect
Google Cloud Project Link
Where did you find the code that you used and pasted? Because the one present in the official documentation is different.
This portion of code is the one in the tutorial you linked, try to use the client library and post the error logs if get any!
require __DIR__ . '/vendor/autoload.php';
use Google\Cloud\Storage\StorageClient;
$projectId = 'YOUR_PROJECT_ID';
$storage = new StorageClient(['projectId' => $projectId]);
$bucketName = 'my-new-bucket';
$bucket = $storage->createBucket($bucketName);
echo 'Bucket ' . $bucket->name() . ' created.';
Remember that bucket name should be unique and therefore I would advice you to test it with a long complex name to avoid to hit already used names, and always test the result of the operation.
UPDATE
I tested also your code and it is working as well, therefore I believe that is an error in the setup of the environment.
Did you get any error while running the composer require google/cloud-storage? Because the class that is missing Google\Auth\Cache\MemoryCacheItemPool is part of Psr that is installed by the composer
[...]
Installing psr/cache (1.0.1)
Loading from cache
[...]
UPDATE2
Matthew M found the error in its configuration and posted:
Finally resolved the issue. I'm using CodeKit in my working
environment and it looks like it is changing something when it
compiles. Ran an uncompiled version and it's working fine.

Travis-CI: Class not found even when using autoloader

Im kind of new with Travis, and I am expreimenting with it right now. I uploaded have my PHP Project on Github and when I let it test via Travis it fails and gives me this error.
PHP Fatal error: Class 'controllers\Welcome' not found in /home/travis/build/ezylot/PHPSkeleton/tests/controllers/welcomeTest.php on line 4
I use a autoloader to load the classes, and it is no problem on my local machine. I include the autoloader in bootsrap.php with the bootstrap in the PHPUnit Konfiguration-XML File.
<?php
if (!#include __DIR__ . '/../vendor/autoload.php') {
die('You must set up the project dependencies, run the following commands:
wget http://getcomposer.org/composer.phar
php composer.phar install');
}
?>
You are most likely developing on OSX which has case insensitive filesystem and tests pass. Travis uses case sensitive file system. Try renaming app/controllers/welcome.php to app/controllers/Welcome.php.
In general it is good idea to follow PSR-1 standard to avoid autoloading issues.
I had a short php open tag at the top of the class file.
<?
as opposed to
<?php
This broke it on the remote, but not on my local. Which is weird, because I would've expected it to break locally too.
Putting this out there in case someone else is in the same odd situation.

Require paths not working using google api php library

My problem is the next one,
I tried to integrate the google login using OAuth 2.0 feature into my company backend.
I tested it on my domain , www.gabrielestevez.com, everything here works perfect, there is no problem with the require paths, everything runs smothly
But , the company backend directories has the following structure
I'm using a mvc framework developed by me , the Google_SL.php file contains the class where I make the first two require_once
require_once 'Google/Client.php';
require_once 'Google/Service/Oauth2.php';
which works fine, but then when it goes to the client.php and is trying to load this class
require_once 'Google/Auth/AssertionCredentials.php';
is not working , this is the error
An error occurred in script '/home/xxx/public_html/admin/hmf/Core/library/auth/Google/Client.php' on line 18: require_once(Google/Auth/AssertionCredentials.php) [function.require-once]: failed to open stream: No such file or directory
Date/Time: 9-19-2014 11:50:29
, I don't want to change manually all the path within this library because I know there is got to be a better solution to this
any input is appreciated.
for future reference
I fixed my issue using this
set_include_path($_SERVER['DOCUMENT_ROOT'] . '/admin/hmf/Core/library/auth/' . PATH_SEPARATOR . get_include_path());
Try use __DIR__ to get the current directory of the script. Not exactly sure where your AssertionCredentials.php is, but try something like
require_once(__DIR__ . '/Google/Auth/AssertionCredentials.php');

Phalcon PHP Models not being loaded

I have Phalcon php micro application setup on my dev machine and it is working fine. However, I've pushed it to the production machine and it is saying it can't find any of the model classes. I get the error
Fatal error: Class 'ItemType' not found in /var/www/html/api/index.php on line 115
The strange thing is nothing has changed except for the password to the database which I've updated so the app can log in.
I've setup all my registered directories also
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(
__DIR__ . '/models/',
__DIR__ . '/decorators'
))->register();
What would be the reason for this?
Okay, so just found out that my dev machine is handling the file name differently. It is case sensitive on the amazon machine.
My itemtype.php file needed to be ItemType.php. This goes with all model files.
Face palm.

Categories