I have a php script which runs inside a docker (The php version is 7.2.34 on orcalelinux. ) it uses dns_get_records to fetch spf records for domains. For one particular domain it throws a warning:
Warning dns_get_record(): a temporary server error has occurred on line 7
and returns blank result.
I tried to run same script on php:7.2-fpm-alpine the result is same but a different warning:
Warning: dns_get_record(): Unable to parse DNS data received on line 7
But When I run the script on my wsl linux (Ubuntu with php version 7.2.34) the script executes without warning and returns valid result for same domain
Why is same php function behaving differently on three different environment, and how it can be fixed?
My host operating system is windows 11
Here is php script:
<?php
/* do some stuff*/
$spf = dns_get_record('somedomain',DNS_TXT);
print("---------------------------------SMC SPF record---------------------------------\n");
print("\n$spf\n");
print("---------------------------------SMC SPF record---------------------------------\n");
?>
I cannot expose domain name due to privacy issue.
After much research I found that docker from windows is messing up the name servers in the container so the domain name was not able to get resolved properly hence the temporary error. so I had to edit /etc/resolve.conf in my container to
1.1.1.1
and it started working properly.
I still face issues with curl based APIs in the container so I have decided to run docker inside wsl2 instead.
Related
I got a strange behavior. I am using xampp installed on Win7 and PHPMailer class.
When I run a simple .php script to send a mail from the browser, all goes well but if I run the same script using command prompt with php sufix (c:..... php c:\xampp\htdocs......script.php) i got the following error message
"Helo command rejected: need fully-qualified hostname"
Any ideea why?
I can see in ECHLO that when run from browser i got the right server address (my hostname) but when i access the script from command promt i got as a host name the machine name. Can this be changed or set-up to run like from the browser? I guess this is the issue, the hostname.
Thank you
As the others have mentioned, when you're not in an HTTP environment, and if your host name is not set correctly, or is unavailable to PHP for some reason, there may be difficulty obtaining the host name that's used in HELO/EHLO commands. You can provide one explicitly by setting the Hostname property:
$mail->Hostname = 'myserver.example.com';
Note that this is different to the Host and Helo properties; see the docs for the differences.
Most likely the script relies on some environment variable to use as its own hostname, probably $_SERVER['HTTP_HOST']. This will be set when running from your webserver, but not over command line because it's not an HTTP environment.
If you enable full error reporting you may see something like this in the error output:
PHP Notice: Undefined index: HTTP_HOST in script.php
You could force the variable to exist from the command line, like this:
HTTP_HOST=example.com php -f script.php
To compile PHP 7.1.X on Windows I use steps written here:
https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2
When I try to update dependencies with following command:
phpsdk_deps -u
I get following error:
D:\php-sdk2\php-sdk-binary-tools\phpdev\vc14\x64_71_2\php-7.1.15-src
$ phpsdk_deps -u
Fatal error: Uncaught SDK\Exception: Failed to fetch supported
branches
This is happening for almost two weeks now.
You're having network trouble.
If you open up the Config.php file at this line, you'll see that the Config tries to load the URI https://windows.php.net/downloads/php-sdk/deps/series/, and pick the correct txt file from there, in order to download the right dependencies. The exception you get means that this cannot be properly fetched.
The solution in my case was to use the company proxy (command line wasn't using it, so it cannot properly resolve & reach the above URL, and so the Config.php gets an empty response). How to do so might change depending on the network settings you use. In my case, I simply visited the URL above in Firefox (which is properly configured by the company), opened up the network pannel, get the IP of the website from there (which is actually the IP of the proxy Firefox was told to use by the company settings), and add the IP hostname entry in my host file (C:\Windows\System32\Drivers\etc\host) so it looks like 10.1.2.3 windows.php.net
Then I rerun the Config script, and boom, it managed to retrieve the txt files and the dependencies.
Another solution can be to retrieve all the dependencies listed in the txt file that corresponds to your setup, but it's a bit tedious...
I can execute my php scrape file by typing in the address bar:
domain.com/scrape.php
However, I try to use cron job on my shared server on host gator by this command:
/usr/bin/php-cli public_html/scrape.php
I got this error message:
Fatal error: Call to undefined function GuzzleHttp\Handler\curl_reset() in /home4/username/public_html/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 78
I already update my php version to stable 5.6 or even 5.7 version also same error. I think that it should not be php version error because I still can execute the file from browser right ?
Also I cannot reboot server Apache because hostgator support said they cannot reboot it until the server is totally down...
Any help please ! Thank you !
I ran into this problem last week on my own server. As it turned out, my browser was looking at one installation of PHP and cron was looking at a 2nd installation of PHP. One way to check is to run a PHP script through your browser that executes phpinfo(). That will tell you what the browser is running. Have cron do the same and save the results. Compare the two and make sure they're pointing to the same installation of PHP. Don't just check versions. Check install paths and loaded modules. Cheers.
I'm venturing out of the world of .NET and into the world of open-source. However, I've hit a few roadblocks while trying to get my development environment set up. And I'm kind of stuck on the most recent one.
I have installed: Apache 2.2, php 5.3.2, and mySQL 5.1.48
everything is working pretty much; apache is serving up PHP pages, and I'm able to create databases and tables in mySQL, however, I can't seem to get php to communicate correctly with mySQL. My php.ini has these lines un-commented:
extension=php_mysql.dll
extension=php_mysqli.dll
However, I keep getting this error message:
Warning: mysqli_connect(): (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\mysql_test.php on line 15
any help would be greatly appreciated.
(btw, the php code runs properly when I put it on my web host)
This is most likely a configuration problem with the MySql server. It sounds like it either isn't listening on the correct port or something else is going on with the connection. You have the extensions loaded correctly because PHP is able to find the mysql functions. I would make sure you don't have a firewall blocking any of the requisite ports (actually, just try turning off your firewall and see what happens...just don't forget to turn it back on ;-) ). Also make sure if you are following a tutorial you didn't deviate from the MySQL setup instructions at all. If those don't work, post an update and we can try again.
This looks like bug #45150 : MySQL functions cannot be used with 5.3.x on Vista when using "localhost" -- I've had this problem once, and it took me some time to figure out what was causing it...
If you are working with Windows Vista (and possibly seven ?), and trying to connect to MySQL using "localhost" as host, try to replace that by the corresponding IP address : "127.0.0.1"
Or try to edit the hosts file, and to un-comment the line that corresponds to localhost in IPv4 :
127.0.0.1 localhost
(Remove the # at the beginning of the line)
Or to comment the line that corresponds to localhost in IPv6 :
#::1 localhost
(Add a # at the beginning of the line)
And here's an interesting article about that : PHP 5.3 and MySQL connectivity problem
Use XAMPP - it'll remove any headaches like this for local development.
XAMPP is a very easy to install Apache Distribution for Linux, Solaris, Windows and Mac OS X. The package includes the Apache web server, MySQL, PHP, Perl, a FTP server and phpMyAdmin.
I have recently upgraded from Apache 1.26 and PHP 4.3 to 2.2.11 and 5.2.9 respectively. With my original setup I had a scheduled task set to run every Sunday for a weekly newsletter. It would connect to my database (Interbase/Firebird) to find out what events were opening for the following week and get the list of addresses the email will be sent to. Of course, I had to change how PHP the task was setup since command line execution has changed slightly from version 4 to 5. Once that was fixed the real problem reared it's head.
Now when executing any script from the command line I cannot connect to my database. I receive the following error from ibase_errmsg: Unable to complete network request to host "localhost". Failed to locate host machice. Undefined service gds_db/tcp.
The same script works perfectly from the browser. Also, the database connect code is used all through my site for logging in, getting records, and updating records.
If anyone has any idea why a script will not connect to the database when executed from the command line, please help.
Sorry for the post everyone. I have answered that question. I had to copy my fbclient.dll file in to my PHP folder and rename it gds32.dll.
Does anyone know why I had to do this for executing command line scripts only, and not for scripts that run in the browser?