PHP: get_headers empty result - php

I have a script that check if the file exist on another server with get_headers. I've two servers on one server it works, on the other I get an empty response from get_headers.
my code:
$myurl='http://stackoverflow.com/';
$header = get_headers($myurl);
print_r($header);
php version
PHP 5.3.3-7+squeeze14 with Suhosin-Patch (cli) (built: Aug 6 2012 14:18:06)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
solution:
No sure what it was, my apache log was full of those errors
failed to open stream: php_network_getaddresses: getaddrinfo failed: System error
after a reboot it all went away and get_headers is working now.

Check if allow_url_fopen is on.
php --info | grep allow_url_fopen

Related

Require_once fails after hours of running php and php-fpm requires a restart

We have a strange issue that has started happening on one of our servers.
after about 24 hours an initial script that has a require_once in it suddenly starts failing.
it may not fail every time. as we use the same script to load images it may be that 3 or 4 random images would fail every time the page loads.
I've added the script and the error although there is no errors until about 24 hours after php fpm has started so please don't try and debug the code
gareth#app8 /var/log/nginx % php -v
PHP 7.4.3 (cli) (built: Feb 23 2020 07:24:28) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
gareth#app8 /var/log/nginx % nginx -v
nginx version: nginx/1.17.8
2020/03/05 04:24:38 [error] 37086#37086: *249519 FastCGI sent in stderr: "PHP message: PHP Fatal error: require_once(): Failed opening required '../system/bootstrap.php' (include_path='.:/usr/share/php') in /var/www/mindworks.co.uk/public_html/bootstrap.php on line 12" while reading response header from upstream, client: 162.158.89.232, server: mindworks.co.uk, request: "GET /$
<?php
/**
* must define URL_ROOT in here for resources
* to be loaded in correctly, this has moved out
* of Config.
*/
define('URL_ROOT', '/');
/**
* load the system's bootstrap.
*/
require_once '../system/bootstrap.php';

"Which php" showing incorrect path in mac os

I am doing "which php" in my mac book and its giving me the output as below :-
/usr/bin/php
While in path variable its showing me :-
~ manishk$ echo $PATH
/Applications/XAMPP/xamppfiles/bin/php-5.6.24:/usr/local/rvm/gems/ruby-2.1.2/bin:
Which php should point to php-5.6.24 .
Even php --version is giving me
PHP 5.4.30 (cli) (built: Jul 29 2014 23:43:29)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
I don't know where to set it to correct it .
The $PATH variable is ment as a list of directories, where your command binaries can be found. So, you have to add the directory where the php binary is located.
For XAMPP this means, you'll have to add the following path to your $PATH variable:
/Applications/XAMPP/bin
As this is a symlink to xamppfiles/bin, you can also use this one:
/Applications/XAMPP/xamppfiles/bin

MySQLi reported missing, only in console

I'm using XAMPP and PHP CLI to test my PHP script locally. The problematic line (the line 98) in db.php is:
$this->mysqli = new mysqli($host, $user, $pass, $dbname, $port);
And the error is:
No such file or directory in /path/to/my/file/db.php on line 98
This problem only appears when I execute a PHP file that requires db.php in Terminal. It works fine when I run it in browser. How come?
The CLI command I use is:
php test.php
Well, that's a very simple command. Is there anything I missed?
Note: I'm using Mac OS X 10.10.1
PHP version:
PHP 5.5.14 (cli) (built: Sep 9 2014 19:09:25)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies

Fatal error: Class 'COM' not found PHP. Win7 - Apache - PHP

$myapp = new COM("word.application");
// returns a fatal error: "Class 'COM' not found in c:/www/comConnector.php"
shell_exec("whoami");
//returns "NT authority/system"
My system setup
Win7 Pro
Apache Server version: Apache/2.2.23 (Win32)
PHP
PHP 5.3.16 (cli) (built: Aug 15 2012 20:06:57)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
Add COM support in php.ini:
[COM_DOT_NET]
extension=php_com_dotnet.dll
Since you are using PHP 5.3.16, make sure that you are pointing to the global namespace:
$myapp = new \COM("word.application");
Even though your PHP file might be in global namespace already, but it's a good practice.

Segmentation Fault error in PHP, using SOAP to connect to SalesForce

I'm integrating my software (PHP) with SalesForce, using the SalesForce PHP Toolkit.
So far, everything's worked great, but when I started writing the code to call convertLead(), I got a "Segmentation Fault" error.
This is the code I'm running:
require_once('../salesforce/SforceEnterpriseClient.php');
ini_set('soap.wsdl_cache_enabled', 0);
$SForce = new SforceEnterpriseClient();
$result = $SForce->createConnection('../salesforce/enterprise.wsdl.xml');
$result = $SForce->login('user', 'pass+token');
echo "Logged In!";
$data = array(
'convertedStatus' => 'Converted',
'leadId' => '00QC000000mDcmJMAS'
);
$result = $SForce->convertLead(array($data));
That's it. And i'm getting a Segmentation Fault. I tried using StdClass instead of a keyed array, same thing. The convertLead method in the SF toolkit is really simple, it just calls the same method into a SoapClient instance...
NOTE: I'm running this script from the CLI, not through Apache.
UPDATE: Just tried running "strace" with my script. The last lines of it are:
close(4) = 0
write(1, "Logged IN!", 10Logged IN!) = 10
open("error_log", O_WRONLY|O_CREAT|O_APPEND, 0644) = 4
--- SIGSEGV (Segmentation fault) # 0 (0) ---
+++ killed by SIGSEGV +++
Also, in case it's relevant:
php --version
PHP 5.2.13 (cli) (built: Jul 17 2010 22:01:13)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator
with the ionCube PHP Loader v3.3.20, Copyright (c) 2002-2010, by ionCube Ltd., and
with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies
This also happens in my dev machine (Windows), so I doubt it's the Accelerators or anything like that:
php --version
PHP 5.2.13 (cli) (built: Feb 24 2010 14:37:44)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
This may or may not be specific to SalesForce. Probably not, seems like a bug in the SOAP PHP library. Maybe the request/response are broken, but I can't see those because they're HTTPS.
Any ideas how I can go about diagnosing (or more importantly, working around) this issue?
Thank!
Daniel
There is a bug (still after 4 years) in the PHP soap extension. It has to do with how it handles WSDL caching. Disabling caching with ini_set() does not work. You also need to turn off caching for your particular client instance.
return new SforceEnterpriseClient('../salesforce/enterprise.wsdl.xml', array(
'cache_wsdl' => WSDL_CACHE_NONE
));
This is true even when using the native PHP SoapClient class.
Ok, this doesn't solve the underlying issue, but, in case someone got this same problem with SalesForce and PHP...
Despite what the documentation implies, fields SendNotificationEmail and OverwriteLeadSource ARE MANDATORY, you MUST specify them in the call.
Not doing so should give you a nice error, not a SegFault, but still, that solves it.

Categories