I try to the get source of a page using file_get_contents() via proxy using the following code
$aContext = array(
'http' => array(
'proxy' => 'tcp://proxy.ssn.net:8080',
'request_fulluri' => true,
),);
$cxContext = stream_context_create($aContext);
$homepage = file_get_contents('http://www.indiaglitz.com/channels/tamil/reviews.asp', False, $cxContext);
echo $homepage;
This works when i execute the php file via terminal, but i don't get the output when i run the file through browser using httpd(Apache 2).
This works in Apache2 installed in Ubuntu, but not in httpd installed in Fedora 17.
Where is the mistake??
The most common cause of this is SELinux not permitting httpd to make network connections.
To resolve it, you need to change an SELinux boolean value (which will automatically persist across reboots). You may also want to restart httpd to reset the proxy worker, although this isn't strictly required.
setsebool -P httpd_can_network_connect 1
So I see that one server works on your ubuntu, but not on the fedora server. The fedora server probably has the option Allow_url_fopen (file_get_contents uses fopen()) turned off in its php settings. http://php.net/manual/en/filesystem.configuration.php
BUT! Don't change that security setting. If you want to download something, curl works well without opening the security hole.
Related
I an creating a PWA app and its working fine, but when I tried to upload on server I stuck on error. On windows local server, everything is fine even notifications, and I dont know much putty/linux commands.
check here my phpinfo file.
I am tring to upload to amazon ec2 server. I installed apache, php, ssl and other required things. And its working file except notifications.
When I call my notification file, I got 503 response. I installed composer, installed everything. I used this github library.
As I understand, I stuck on gmp extension, When I open phpinfo() I didnt see gmp over there. I installed gmp using sudo yum install php-gmp and also I see a file in php.d named as 20-gmp.ini and it included extension=gmp. Also restarted apache server using sudo apachectl stop, sudo apachectl start.
But still I am getting error. And I coudnt see gmp in phpinfo().
notificationb.php
<?php
require __DIR__ . '/vendor/autoload.php';
use Minishlink\WebPush\WebPush;
use Minishlink\WebPush\Subscription;
$subscription = Subscription::create(json_decode(file_get_contents('php://input'), true));
print_r($subscription);
$auth = array(
'VAPID' => array(
'subject' => 'https://github.com/Minishlink/web-push-php-example/',
'publicKey' => file_get_contents(__DIR__ . '/scripts/keys/public_key.txt'), // don't forget that your public key also lives in app.js
'privateKey' => file_get_contents(__DIR__ . '/scripts/keys/private_key.txt'), // in the real world, this would be in a secret file
),
);
$webPush = new WebPush($auth);
$res = $webPush->sendNotification(
$subscription,
"Welcome to Kaya. You can book Appointments and many more."
);
foreach ($webPush->flush() as $report) {
$endpoint = $report->getRequest()->getUri()->__toString();
if ($report->isSuccess()) {
echo "[v] Message sent successfully for subscription {$endpoint}.";
} else {
echo "[x] Message failed to sent for subscription {$endpoint}: {$report->getReason()}";
}
}
?>
If you need any thing, let me know in command. I will update here.
Edit 1: Also I tried to add gmp extension in php.ini in /etc/php.ini but still not added.
I think I am getting error on $subscription = Subscription::create(json_decode(file_get_contents('php://input'), true));
I know I am commenting my own question, As I was searching this answer for 3-4 days I think I should share this info with everyone.
The issue is, In linux, PHP have different-different configuration files. The main configuration file is php.ini. And it include other extensions after loading this file and override mail file. These additional configuration are located in /etc/php.d/ (in my case, which is common for mostly).
So just restarting apache server in not enough. We need to also restart php-fpm.
To restart php-fpm: sudo service php-fpm restart
And then restart apache: sudo apachectn restart
You can check more here
To apply change in php.ini, you need to restart apache server and also restart php.
sudo service php-fpm restart
sudo apachectn restart
Also sometime it took time to apply changes to server.
I have a local WordPress installation running at: https://catalogue3.test.
Note that all .test domains should resolve to localhost, as I use Laravel valet. When I execute the following code in my Laravel project however, I get an exception as shown below.
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', "https://catalogue3.test", ['verify' => false]);
ConnectException
cURL error 6: Could not resolve: catalogue3.test (Domain name not
found) (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
When I run the command below in the terminal, the WordPress page is displayed.
curl https://catalogue3.test/ --insecure
Add
ip catalogue3.test
to your /etc/hosts file
I tried to add the domain to hosts and I tried to change dns in network settings, this answer is what worked for me.
Quick way to check if this is your problem is to do: curl --version
and php --ri curl
The versions should match. If they don't it's probably because brew
has installed curl-openssl. This can be removed by doing:
brew uninstall curl-openssl --ignore-dependencies
Maybe there's a way to configure the installed curl-openssl properly -
I've not investigated this yet.
I solved this adding catalogue3.test to /etc/hosts, even if I was using DnsMasq, and in theory, I wouldn't need it.
In my case (on macos) I had to add 127.0.0.1 as the first DNS server option in my WiFi settings.
Some useful info here too: https://github.com/laravel/valet/issues/736
I updated my curl to work on https. It does work on terminal however when I use cUrl in php it doesn't work for any https based url.
The error code i get is 77. I have looked into other solutions but no solution is working at all.
I have already tried adding verifyHost, SSL v 6, return transfer nothing works
A simple code is
$ch = curl_init("https://www.google.com");
$response = curl_exec($ch);
$error = curl_error($ch);
$number = curl_errno($ch);
curl_close($ch);
$response = array(
'Result' => array(
'error'=> $error,
'number' => $number,
//'message'=>$fields,
'count'=> $response
));
$this->jsonOutput($response);
In terminal curl https://www.google.com works fine.
What is going on, the curl in php was working just fine before.
As you are using yum, i assume you are working on a CentOS distro.
I have made a brief research and it seems it could be an issues with the NSS centos package, triggered by your yum update. You could try some basic process restart.
Try to restart your httpd service:
service httpd restart
Or via apache:
apachectl stop
apachectl start
and your php-fpm
sudo service php-fpm restart
My dev server is Debian Squeeze and I'm running Gearman 1.1.5 which I compiled from source along with the php pecl extension v1.1.1
If I run the reverse_client.php script I get the GEARMAN_COULD_NOT_CONNECT error.
PHP Warning: GearmanClient::do(): send_packet(GEARMAN_COULD_NOT_CONNECT) Failed to send server-options packet -> libgearman/connection.cc:430 in /home/bealers/build/gearman-1.1.1/examples/reverse_client.php on line 26
There are a few similar posts on here about this and they all point to GM not running.
It is definitely running.
I'm starting it with these params:
PARAMS="--queue-type=MySQL --mysql-db=test_db --mysql-user=gearman --mysql-password=gearman"
If I drop the gearman_queue table in test_db then restart the daemon the table is recreated, so its mysql connection is fine and it's clearly starting.
I can also telnet to 4730 on localhost, so there's no firewall issue.
Initially GM had problems starting because it was starting before mysql, so I edited the init script
### BEGIN INIT INFO
# Provides: gearman-job-server
# Required-Start: $network $remote_fs $syslog mysql
and an update-rd.c gearman-job-server defaults sets it to start after and it starts fine on boot up now.
The only other thing I can think of is that initially I'd installed via apt but the version was to old so I removed it and compiled from source. /usr/sbin/gearmand no longer exists the only version is /usr/local/sbin/gearmand
ps ax | grep gearman shows only one process running.
Netstat shows only one process running`
tcp 0 0 *:4730 *:* LISTEN 2325/gearmand
The PECL lib seems fine:
php -i | grep gearman
/etc/php5/cli/conf.d/gearman.ini,
gearman
gearman support => enabled
libgearman version => 1.1.5
I'm out of ideas
I had the same problem and recently solved them after a couple days of frustration (hard to troubleshoot since there are three processes to worry about :-)
It appears (at least in my case) that the PHP documentation for GearmanClient::addServer() and GearmanWorker::addServer() is incorrect. Specifically, the docs seem to imply that hostname and port number are optional and that it will use localhost and port 4730 as defaults if you do not specify them. This never works - it suddenly occurred to me today to try explicitly specifying them for both client and worker processes and everything started working.
Try specifying all values for hostnames and ports and see if this works for you.
In case if you have used something like this
$client->addServers('127.0.0.1', 4730);
or
$client->addServers();
use something like this
$client->addServers('127.0.0.1:4730');
PS - I have used localhost IP, this can be replaced with actual host IP.
In my case it's little different. I got this same error when I had my addServer code inside the loop.
$client = new GearmanClient();
for ($i=0; $i<100000; $i++) {
$client->addServer("127.0.0.1", 4730);
$data = json_encode(array('job_id' => $i, 'task_name' => 'send-email'));
$client->addTaskBackground('sendEmail', $data);
}
$client->runTasks();
And this fixed it for me:
$client = new GearmanClient();
$client->addServer("127.0.0.1", 4730);
for ($i=0; $i<100000; $i++) {
$data = json_encode(array('job_id' => $i, 'task_name' => 'send-email'));
$client->addTaskBackground('sendEmail', $data);
}
$client->runTasks();
May be this could help someone.
If you want to use single server, you can use
$client->addServer($host, $port)
e.g. $client->addServer('127.0.0.1', 4730)
http://php.net/manual/en/gearmanclient.addserver.php
If you want to use multiple server, then you can use
$client->addServers($host1:$port1, $host2:$port2, $host3:$port3)
e.g. $client->addServers('127.0.0.1:4730', '127.0.0.2:8080')
http://php.net/manual/en/gearmanclient.addservers.php
When I go to /fileDownload I receive a 500 Internal Server Error - RuntimeException:
The process stopped because of a "0" signal.
Controller Action:
public function fileAction()
{
$html = $this->render('MyBundle:Downloads:file.html.twig', array(
'fileNumber' => '1234'
));
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="file.pdf"'
)
);
}
I've used terminal commands for WKHTMLTOPDF and it has successfully generated the PDF. It just will not work in Symfony2 app.
In my config.yml:
knp_snappy:
pdf:
enabled: true
binary: /usr/local/bin/wkhtmltopdf
options: []
I'm assuming Symfony is issuing an exec() at some stage. You need to get the exact command line error returned. The fact it works for you in a terminal session doesn't necessarily mean it will work when a different user/process is running it.
Check permissions on wkhtmltopdf that apache or whoever is running your web server has access to run the command.
Also, check this question out wkhtmltopdf: cannot connect to X server and also the first post here: http://geekisland.org/index.php?m=05&y=11&entry=entry110518-114630
X Server is required to run certain builds of wkhtmltopdf and it is not present when running via cron or from within an apache process. If this is the case you need to use the bash wrapper in the first link above.
Be sure that wkhtmltopdf is indeed in the folder you specify, with correct permissions: /usr/local/bin/wkhtmltopdf
I am successfully using KNP Snappy Bundle with Symfony 2.0, try using RenderView instead of render when generating the html (check my code that is working):
Controller:
$html = $this->renderView('YOPYourOwnPoetBundle:thePoet:poemPDF.html.twig', array(
'poem' => $customizedPoem,
'fontType' => $fontType,
'fontSize' => $formData['fontSize'],
'fontWeight' => $fontWeight,
'fontStyle' => $fontStyle,
));
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="'.$session->get('poemTitle').'.pdf"',
)
);
I had this same issue and i finally solved it, my advice is if you installed the wkhtmltopdf lib from your OS repos then remove it, and download the static version from the google code website, and don't use version 11rc, use the version 9 static lib, it's the one that worked with me.
http://code.google.com/p/wkhtmltopdf/downloads/list
It looks like the selinux is blocking your command, I had the same issue once but I solved it by disabling the SELinux and now I'm able to generate the pdf file using wkhtmltopdf+php.
exec("/usr/local/bin/wkhtmltopdf http://www.google.com /var/www/html/google.pdf");
To disable selinux run setenforce 0,
try again and see if it works.
Re-enable it with setenforce 1
But disabling selinux is not the best solution for this, you need to extend it instead using audit2allow, it will automatically create a custom policy module that will resolve this issue,
First install audit2allo if not already installed
yum -y install policycoreutils-python
grep httpd_t /var/log/audit/audit.log | audit2allow -m httpdlocal > httpd.te
checkmodule -M -m -o httpdlocal.mod httpd.te
semodule_package -o httpdlocal.pp -m httpdlocal.mod
semodule -i httpdlocal.pp
try again and see if it works
I experienced the same issue on same scenario with wkhtmltopdf. And I got rid of with the following command:
setsebool httpd_execmem on