I am trying to make console command to add data to the APC cache, but so far without any success.
This code works perfectly when I run it as a standard action (controller/action):
public function actionUpdateExchangeRate()
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://openexchangerates.org/api/latest.json?app_id=xxxxxxx',
CURLOPT_USERAGENT => 'Exchange Rates'
));
$json = curl_exec($curl);
curl_close($curl);
$rates = json_decode($json);
Yii::$app->cache->set('rates', $rates->rates);
}
I made a command with the same code, and when I try to set the cache, nothing is happening.
var_dump('<pre>', Yii::$app->cache->set('rates', $rates->rates), '</pre>');die;
Dump give true when run as a controler/action, and false when run from the command.
In the console.php I added this configuration to the component (it is same in the web.php):
'cache' => [
'class' => 'yii\caching\ApcCache',
'keyPrefix' => 'test',
'useApcu' => true
],
PHP version is:
PHP 7.2.4-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Apr 5 2018 08:53:57) ( NTS )
Any idea what I am doing wrong here?
Make sure that you have enabled apc.enable_cli in php.ini.
But using ApcCache for console does not make much sense. APCu cache is per process, so it will be removed anyway after command is ended and console commands will not share cache with web requests.
Mostly for testing and debugging. Setting this enables APC for the CLI version of PHP. Under normal circumstances, it is not ideal to create, populate and destroy the APC cache on every CLI request, but for various test scenarios it is useful to be able to enable APC for the CLI version of PHP easily.
https://secure.php.net/manual/en/apcu.configuration.php#ini.apcu.enable-cli
I'm thinking I installed this wrong, but keep getting the same error. Installed league/flysystem-aws-s3-v3. S3 creds are setup in .env file.
Added these to the require in composer.
"aws/aws-sdk-php"
"aws/aws-sdk-php-laravel": "~3.0"
--------------------------------------------
Code:
$s3 = \Storage::disk('s3');
$s3->put($location, file_get_contents($image), 'public');
Getting the following error:
exception 'InvalidArgumentException' with message 'Missing required client configuration options:
' in /var/www/laravel/vendor/aws/aws-sdk-php/src/ClientResolver.php:328
Did some research online and couldn't find a solution.
Try to update :
composer update
Try This: go into config/filesystems.php and eliminate any env that encompasses a value.
For example mine showed 'cloud' => env('FILESYSTEM_CLOUD', 's3'),
so I changed it into 'cloud' => 'FILESYSTEM_CLOUD', 's3',
Do this to ALL values in this file, INCLUDING the S3 key, secret, region, and bucket. After that it should get you up and going.
I believe the issue is with Caching the values as Null rather than the actual edited values.
I am attempting to use a service account with Google's API to add a calendar event using php. I have this working perfectly on a site already. When i moved it to another site on the same server, i suddenly began to receive the following error messages:
~PHP Warning: mkdir(): Permission denied in Google/Cache/File.php
~Uncaught exception 'Google_Cache_Exception' with message 'Could not create storage directory: in Google/Cache/File.php
The two environments are identical as far as i can tell
~Same server
~Same permissions on all files/folders
~Same credentials
~Both URLS authorized in Google's console
I checked with my server to see if something in the upvoted answer here could be the issue, but was assured that everything was set up correctly.
I've done a lot of searching and reading, but can't imagine what might be causing these errors when everything works perfectly from the other site.
Any help would be much appreciated!
In case anyone comes upon this: I solved this by following the advise given here:
A client error occurred: Could not create storage directory: /tmp/Google_Client/00
specifically, i manually added nested folders (google and cache) inside my tmp directory and then set the path to it for google using this code (from the link above):
$config = new Google_Config();
$config->setClassConfig('Google_Cache_File', array('directory' => '../../tmp/google/cache'));
// Here I set a relative folder to avoid pb on permissions to a folder like /tmp that is not permitted on my mutualised host
$client = new Google_Client($config);
Add this PHP code to your script:
$client = new Google_Client();
$client->setCache(new Google_Cache_File('/path/to/shared/cache'));
In case also that anyone needs to do this. I'm working with Codeigniter and recently moved to osx el capitan on mac from windows 7. My google cache folder had the admin permissions read and write but the error persists: mkdir permission denied, on google/cache/file.php
I looked at my code where I load the google api and added>
$config = new Google_Config();
$config->setClassConfig('Google_Cache_File', array('directory' => 'application/third_party/Google/src/Google/Cache/'));
$client = new Google_Client($config);
So with those line you set your cache folder.
Hope this helps in the future as It helped me.
When I try to use GMail SMTP for sending email via Laravel, I encounter the following error:
Swift_TransportException
Connection could not be established with host smtp.gmail.com [Connection timed out #110]
It is the trace of the error:
...
}
$this->_stream = #stream_socket_client($host.':'.$this->_params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, stream_context_create($options));
if (false === $this->_stream) {
throw new Swift_TransportException(
'Connection could not be established with host ' . $this->_params['host'] .
' [' . $errstr . ' #' . $errno . ']'...
and here are my configuration for mail:
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => 'some#example.ir', 'name' => 'some'),
'encryption' => 'tls',
'username' => 'myemail#gmail.com',
'password' => 'mypassword',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false
I use a shared host and the port 587 on localhost is open.
I had the same problem and I resolved it in this way:
'driver' => 'sendmail',
You need to change only that line.
After doing lot of research I found this one helpful.
https://www.google.com/settings/security/lesssecureapps.
Open the above link .
Click on Enable. And save it.
Then try to send email again.
For me it worked .
Solved mine by changing my .env file as follows:
'driver' => 'sendmail',
Try
'encryption' => 'ssl',
'port' => 465,
The problem is that smtp.gmail.com is resolving an IPv6 address and that google service only listens on IPv4. What you need to do is set the source IP to ensure domains resolve as IPv4 and not IPv6.
The important method:
->setSourceIp('0.0.0.0')
How you might use it in code:
$this->_transport = Swift_SmtpTransport::newInstance
(
'smtp.gmail.com',
465,
'ssl'
)
->setUsername('username')
->setSourceIp('0.0.0.0')
->setPassword('password');
Works for me with same settings except encryption and port. Change to:
'encryption' => ssl,
'port' => 465,
Since this is only for localhost encryption line should also be environment specific. So instead above I did following:
env('MAIL_ENCRYPTION','tls'),
Now you can set this in .env file, which is environment specific and should be in .gitignore
I got the same problem using laravel forge + digitalocean.
I find when i try telnet smtp.gmail.com 465
telnet smtp.gmail.com 465
Trying 2404:6800:4003:c00::6d... # more than 30 sec
Trying 74.125.200.108... # less 1 sec
Connected to smtp.gmail.com.
Maybe is IPv6 that it Connection timed out.
So,I change gai.conf to prioritize ipv4 over ipv6
vi /etc/gai.conf
#For sites which prefer IPv4 connections change the last line to
precedence ::ffff:0:0/96 100
...
# For sites which use site-local IPv4 addresses behind NAT there is
# the problem that even if IPv4 addresses are preferred they do not
# have the same scope and are therefore not sorted first. To change
# this use only these rules:
#
scopev4 ::ffff:169.254.0.0/112 2
scopev4 ::ffff:127.0.0.0/104 2
scopev4 ::ffff:0.0.0.0/96 14
open your .env file and change this
MAIL_DRIVER=smtp
TO
MAIL_DRIVER=sendmail
this fixed my problem, hope it will help you as well.
The error might be due to 2 step verification enabled. In that case you need to create gmail app password and use this as password.
For me after trying all above solution the only thing that worked for my was
Disabling My Firewall and Antivirus temporarily
If it is a non-Google Apps account, definitely enable access from less secure apps as suggested. If you don't do that, it won't work.
If it is a Google Apps account (ie it's a business account) then there is an admin panel that governs access. You will need to make sure it is only specifying access by authentication and not by IP, since if it is by IP your IP presumably is not on the list.
The final thing to try is using the IPv4 address of smtp.gmail.com in place of that domain name in your code. I found that mine would not connect using the domain (because that resolved to an IPv6 address) but would connect when I used the raw IP in its place.
I got the same problem using Swiftmailer
Anyway, a quick dirty hack you should not use would be to edit swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php. In _establishSocketConnection() line 253 replace:
$options = array();
with something like this:
$options = array('ssl' => array('allow_self_signed' => true, 'verify_peer' => false));
This will change the ssl options of stream_context_create() (a few lines below $options):
$this->_stream = #stream_socket_client($host.':'.$this->_params['port'], $errno,
$errstr, $timeout, STREAM_CLIENT_CONNECT, stream_context_create($options));
There is a dirty hack for this You can find it here
Also my ENV is set to
MAIL_DRIVER=smtp
MAIL_HOST=mail.mydomain.com
MAIL_PORT=587
MAIL_USERNAME=noreply#mydomain.com
MAIL_PASSWORD=mypassword
In your terminal use this command
sudo ufw allow in "Postfix Submission"
this enable port 587 for SMTP
you need to create 2 factor auth and custom password in google account. Also don't forget to add custom password for every new host you are using.
For temporary fix you can resolved the issue by updating env file as 'driver' => 'sendmail'
Check your free disk space. On my case, I have 100% used.
I am using MAMP on MAC. I face this Issue Step to Follow to solve this problem on MAC
SMTP MAIL on MAC OS
Create a file to store our credentials:
sudo vim /etc/postfix/sasl_passwd
Add something like this:
smtp.gmail.com:587 username#gmail.com:password
Now run:
sudo postmap /etc/postfix/sasl_passwd
Prepare the postfix main config file:
sudo vim /etc/postfix/main.cf
Add/update these lines
relayhost=smtp.gmail.com:587
smtp_sasl_auth_enable=yes
smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd
smtp_use_tls=yes
smtp_tls_security_level=encrypt
tls_random_source=dev:/dev/urandom
smtp_sasl_security_options = noanonymous
smtp_always_send_ehlo = yes
smtp_sasl_mechanism_filter = plain
Stop/Start the service
sudo postfix stop
sudo postfix start
Check the queue for any errors
mailq
Your .env configuration should look like this
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME="username#gmail.com"
MAIL_PASSWORD="password"
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="username#gmail.com"
MAIL_FROM_NAME="${APP_NAME}"
I try to config a program use xhprof.
When I use php-cli mode or php's built in webServer, the callgraph generate image works well.
But When I use nginx+php-fpm, the dot exec at xhprof_generate_image_by_dot blocks forever.
Then I install the pear Image_Graphviz.Write a simple case like this:
require_once 'Image/GraphViz.php';
$img = new Image_GraphViz();
$img->addNode(
'Node1',
array(
'URL' => 'http://link1',
'label' => 'This is a label',
'shape' => 'box'
)
);
$img->image('png');
php's built in webServer can generate png files ok,but php-fpm block at dot exec forever.
So, can anybody help me? What's wrong with this? Here is some relevant machine information:
The OS: OSX
The graphviz version:2.34.0
The App: nginx1.2.8+php-fpm+php5.4.21+xhprof(the latest version from github)
After reboot my machine.Everything turn to right.
Mystery.