Yii can't find GearmanClient - php

I am trying to create tasks using gearman using GearmanClient class from the gearman-php-extensions. I am able to run below program using command prompt-
//php client.php works fine
<?php
$client= new GearmanClient();
$client->addServer();
$task = $client->do("send", "hi");
?>
But I wan't to run this code in some yii controller. It seems like yii is not able to find the path upto GearmanClient class, but why?
Also I am writing the yii programs in eclipse. As php command and eclipse are both using the same php library, my yii controller should work fine. Instead my browser gives errors like-
PHP warning
include(GearmanClient.php): failed to open stream: No such file or directory
#plus some warnings and the yii stack trace.

This is happening because, the process that is handling the php files is not updated with the latest php.ini configuration. So you just need to restart that process.
Therefore:
If php handler is running as a web server module, then you'll need to restart the web server.
If you have php running as a cgi process, then you'll need to restart that process.

Related

Very slow response if there is an error in laravel view or component

I'm new to laravel and I'm building a pure laravel 9 app(no vue, nodejs or other frameworks just laravel + vanilla js). If I have any kind of error in any laravel view/component/partials the error page response tooks more then 20seconds to appears. If I have an error in any controller/model/config or other laravel's environment files, the same error is superfast. In example if I have a typo in my view layout.blade.php
PHP
#php
ech 'missing a letter';
#endphp
this will throw the error in 20 seconds
if I place a typo in a controller like this
PHP
public function index() {
retur 'missing a letter';
}
this will throw the error instantly.
if this can helps, checking in my console the laravel log file like this
DEBIAN BASH
tail -f /var/www/mylaravelapp/storage/logs/laravel.log
will throw the error in the same time that appears in the laravel error page.
Obviuously is not a big deal, but since I'm working on the appareance of the UI, this will slow down my work so much.
UPDATE
I'm adding a screen of my devtools opened, it simply waits for server response 23 seconds
UPDATE
Some new details, really strange for me, what happens is that in my component I have some pure javascript script in the bottom of the page(around 500 rows). If I delete the scripts the error page will run superfast. I tried to place the scripts directly behind the scripts tags and I tried using the #pushOnce directive with same results. I tried to reduce the amount of code, and the more I reduce the code the more will run faster. I tried to put the script directly in my layout.blade.php that calls the component and it runs superfast, I tried to put the js code like an external script and it runs superfat, so problem happens only with inline JS probably I'm placing the scripts in a wrong way
UPDATE
OK I think this update is important, if I run my laravel app through my apache web server(so not using php artisan) the error page will load superfast, so this cannot be related to some code error. Usually I run my laravel app in this way
php artisan serve --host 192.168.25.209
where 192.168.25.209 is a server in my network that is hosting my laravel app. As #Don't Panic pointed in the comments
"The web server runs only one single-threaded process, so PHP applications will stall if a request is blocked"
So I checked for permissions on cache storage folders, but everything looks good, cache files and logs are correctly written

Symfony messenger can't consume messages

Few weeks ago I set up a Message system with Symfony Messenger and it worked great.
Today I wanted to create new object through message, so I went to my server and type the command to consume message
First I had this result
$ bin/console messenger:consume-messages amqp_notifications
/usr/bin/env: ‘php\r’: No such file or directory
It never happened before with my files, and I never changed the line ending or encoding of my file sin PHPstorm.
I tried to use $ php bin/console messenger:consume-messages amqp_notifications
but then I had this error.
Attempted to load class "AMQPConnection" from the global namespace.
Did you forget a "use" statement?
Pretty weird, because I have have the php-amqp ext installed as you can see on the screenshot of my phpinfo
I didn't change anything in my Message class or Handler.
Also, I tried to call new AMQPConnection() on a random action, just to try, and I didn't get the error.
I'm completely lost with this error this time, as everything is installed.
I use PHP 7.3.1 and symfony Messenger 4.2.2
It seems your second issue was already solved by ccKep on his comment.
The first one is that the specific shebang line #!/usr/bin/env php executes the first php found in the $PATH. So if you already have uninstalled it, which seems the case, or it has a symbolic link to another php version, you can get a wrong result.
Tries to check what is inside the $PATH and replace the PHP path for the correct one. You might get the place running which php.

Swoole server only can be used in PHP CLI mode

I am using Swoole server and slim framework, especially this library:
Slim Swoole Link
I have followed the tutorial, and gives me this error:
Fatal error: Swoole\Server::__construct(): swoole_server only can be used in PHP CLI mode. in /Users/powermilk/Documents/Proyectos/prueba/public/index.php on line 48
the line 48 has the below code:
$http = new swoole_http_server("0.0.0.0", 8081);
I don't understand why happens this if I quit the library code everything works nice, but I am not able to run slim with Swoole.
The server is running over Nginx.
I'm the writer of the library.
Yes, you have to create your "front controller"ish file and execute it from CLI.
Sort of, from terminal, "php name_of_your_file.php" and leave it running.

Phalcon Mongo Class not found error

I attempting to setup Phalcon PHP using a Mongo database connection. I have configured my bootstrap (index.php) file using the following:
// Mongo database connection
$di->set('mongo', function(){
$mongo = new Mongo();
return $mongo->selectDb("phalcon");
}, true);
// Collection Manager
$di->set('collectionManager', function(){
return new \Phalcon\Mvc\Collection\Manager();
});
Whenever I attempt execute an insert fucntion in using this connection, I receive a 500 Internal server error. Now, I have checked my apache server error logs and it states "PHP Fatal error: Class 'Mongo' not found in /var/www/phalcon-mongo/public/index.php on line 17".
I don't know why this request is not processing, according to the documentation given from Phalcon, the connection to mongo DB is setup up as I have displayed above.
If anyone has any advice, please let me know.
i think it's because your installation of Mongo is not valid.
try printing phpinfo() and check if mongo is loaded at all, if not - install it, add to ini files (if you use cli, don't forget to add to cli ini too) and reach the moment, when mongo is fully loaded.
try mongo w/o phalcon. any simple connection/insertation. you can see here: Fatal Error - 'Mongo' class not found that there are problems with apache module version for some people. Try reinstalling different mongo version.
if you can print this out:
echo Phalcon\Version::get();
there should be no problems with phalcon instalation
to validate mongo installation, try any of examples from php.net:
http://www.php.net/manual/en/mongo.tutorial.php
if both installations are valid, then there are problems with your custom code, but before doing anything you have to validate both installations.

SoapClient: faultcode WSDL

When I try to use SoapClient:
try {
$client = new SoapClient('http://someurl/somefile.wsdl');
} catch (SoapFault $e) {
var_dump($e);
}
I have catch error with:
["faultstring"] => "SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://someurl/somefile.wsdl' : failed to load external entity "http://someurl/somefile.wsdl"
["faultcode"] => "WSDL"
I can manually download http://someurl/somefile.wsdl and can file_get_contents for this file. I try to use it before on different computer and it worked. Possible problem with php or apache settings..
ArchLinux with last updates for php and apache. I tried to enable all php extensions.
Were you able to get wsdl using file_get_contents() in browser?
I had similar issue recently in Archlinux with same faultstring, no matter what wsdl file was used. The same code was working without any problem on other Archlinux machine and Windows XP box.
After some research, it came out that problem arose only when I tried to access the page in browser - script accessed from command line worked as expected. Then I changed the script to download the wsdl file directly, using aforementioned file_get_contents() - it gave me a warning "php_network_getaddresses: getaddrinfo failed: Name or service not known".
Few tutorials (on SO, or this one: http://albertech.net/2011/05/fix-php_network_getaddresses-getaddrinfo-failed-name-or-service-not-known/ ) later I haven't fought off the problem yet. But then I discovered what introduced the issues: I had been running NetworkManager since the installation of Arch (to better handle wireless), and few weeks later I've added mysqld and httpd as last to DAEMONS section in rc.conf - it seems this broke DNS resolution for apache.
Having two solutions (go back to starting servers manually or try other network manager) I've switched to wicd and haven't run into the issue again.

Categories