Issue with php dio on Ubuntu and Debian - php

I cannot get PHP dio to work on linux. I receive no error messages, but nothing is output to the serial device when I use dio_write nand reads are always null. I initiate the serial port with
$bbSerialPort = dio_open($portName, O_CREAT | O_RDWR);
This seems to accpt the connection. When I use
dio_write($bbSerialPort, $dataToSend);
it retuns with the number of bytes sent, but nothing is sent. When I use
$data = dio_read($bbSerialPort, 2);
it always returns NULL.
I have tested the /dev/ttyUSB0 port using minicom and all works correctly. I have also tried the same code on both MAC OS and Windows and all works OK.
I am wondering if it is something to do with permissions and owners for the device on the different platforms?
I have tried re-installing both php and thje dio extension on both Debian and Ubuntu - always the same result - no errors but the dio_write never writes anything to the serial device.

When file position of the given file descriptor is at the end, position needs to be set to the beginning of the file if the dio_read() has been called somewhere after the dio_write(). With dio_seek() the position can be set to the beginning (or adjusted for your use case):
\dio_seek($bbSerialPort, 0);
$data = \dio_read($bbSerialPort, 2);

Thanks to Peter, I have finally resolved my issues. It was indeed related to the serial port settings and the way my PHP code accessed the port. The serial port was set to 9600 baud and I was not leaving enough time before reading the reply from my remote system. All working now.

Related

PHP curl request results in white page when the url contains dots or colons

This only happens on my webserver, not on the local system.
I have a curl request like this
ini_set('display_errors', 1);
error_reporting(E_ALL);
$url = 'http://***.***.***.***:8080/api_v1/oauth/token';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$response = curl_exec($ch);
This makes the page loading for a while and just returns a white screen. It is really impossible to show errors, output or just anything else.
Whenever I change the url to another url (existing or not existing) i get proper errors or output if the url makes sense, as long as the url does not contain any dots or colons...
Is there any restriction for the usage or a curlopt I am missing?
I have no control over the target url, I need to consume the api in the ip:port structure.
UPDATE
The problem is not related to the target URL or data coming in: the same problem occurs when I enter a url that makes no sense at all as long as it doesn't contain . or :
I guess it is a setting on the webserver since all my tests work fine on localhost (MAMP)
Unfortunately I have no access to any logs or files except the ones I upload myself (one.com webhosting)
UPDATE 2
Turns out my hoster is blocking all outgoing traffic to implicit IP's and ports other than 80 and 443.
Cancelled my subscription and taking a decent provider now.
Thanks for the help
As #Quasimodo suggests, then I'd take a look in the log-file, if I were you. If you're on a Ubuntu-server using Apache, then look at /var/log/apache2/error.log. A neat trick is to open a terminal and write:
tail -f /var/log/apache2/error.log
This will open a running stream to the terminal. Then you can make your curl-request crash (in your browser) and then go back to the terminal and see what new and juicy errors you have received.
It's most likely some configuration-file on your server. So it would be helpful, if you write a couple of specs from that server, such as:
- Which web server you're using (Apache, Nginx, other)
- PHP version
... You can find all of these information easily using phpinfo.
My best guess is that you need to enable PHP_Curl for your server configuration, - but it is a buck-wild cowboy shot from the hip.
Addition 1
I can see that you've just editted the question (that it thinks for a while and then gives a blank screen). I'd say, that your curl-request might be trying to load a big amount of data, and that your PHP-configuration has a cap at 128mb (or something).
I'd check the PHPinfo for these two values:
max_input_vars
memory_limit
To see if either of them are suspiciously low.
Turns out my hoster is blocking all outgoing traffic to implicit IP's and ports other than 80 and 443. Cancelled my subscription and taking a decent provider now. Thanks for the help

Change serial port baud rate in runtime and strange effect

I've encountered strange problem - I have to change serial port baud rate (from initial 300 baud to something higher) in runtime of PHP code and every time I try, next readed bytes are simply ZEROs.
I've already tried multiple ways of serial connection in PHP:
fopen/fread/fwrite of standard file (in that case "/dev/ttyUSB0"), configured with exec and stty commands
dio_open/dio_read/dio_write, configured with dio_tcsetattr
fopen/fread/fwrite of dio stream (dio.serial type)
I'm pretty sure that there's something wrong in PHP itself, because similar code in Perl works correctly and baud rate doesn't affect reading at all. I've checked strace log of PHP and Perl scripts and they look almost identical in case of serial port configuration, so problem lies somewhere else.
Problem solved by modifying php_dio extension, which - by default - cannot switch baudrates in runtime.

Mantis Bugtracker: File download stops after 4Kb has been downloaded

I'm having an issue with Mantis Bugtracker (version 1.1.8), where file downloads only reach 4 Kb, and then stop. I don't know if this is a problem in the product itself, or in the PHP installation on the server. I've tried disabling output buffering (that was the only value close to 4Kb), but that didn't help.
The files are stored in the database. The application is running on IIS7 on Windows Server 2008 and Sql Server 2005, and the installed version of PHP is 5.2.11.
Does anyone have a solution that might help fix this?
Okay, I think that I'm just going to have to face the fact that I'm an idiot. I had changed the textsize and textlimit properties in php.ini for MSSQL, but I missed the semicolon in the beginning of the lines. I just uncommented those two lines, and now it works like a charm.
; Valid range 0 - 2147483647. Default = 4096.
mssql.textlimit = 2147483647
; Valid range 0 - 2147483647. Default = 4096.
mssql.textsize = 2147483647
OK ... 1st thought would be that it is bizzarly timing out?
You could try setting a max timeout...
Also, knock up an independant bit of code to fetch and download file - to rule out/in any bugs in Mantis ... I use a Mantis but hosted on linux and it all works fine - same vervsion but linux and mysql...
OK A quick serach on mantis's forum gave me: http://www.mantisbt.org/forums/viewtopic.php?f=3&t=4712 which describes exactly what you have happening and it is indeed a specific Windows/ISI/SQL Server thing ;)

Why is the same CURL code failing on one server and yet works on the other one?

The code attempts to grab a test page for example Yahoo.com in this case. I am outputting the var_dump
http://jinimatics.com/test.php (this works)
http://jinimetrix.com/test.php (this does not)
(Curl is installed on both servers along with fairy recent Lamp Stack)
Try to compare whats installed and version differences.
check your server settings with phpinfo();
then you can change settings in php.ini

php access network path under windows

within PHP (XAMPP) installed on a Windows XP Computer Im trying to read a dir which exists on a local network server. Im using is_dir() to check whether it is a dir that I can read.
In Windows Explorer I type \\\server\dir and that dir is being shown.
When I map a network drive a can access it with z:\dir as well.
In PHP I have that script:
<?php if( is_dir($dir){ echo 'success' } ) ?>
For $dir I tried:
/server/dir
//server/dir
\server\dir
\\server\dir
\\\\server\\dir
and
z:\dir
z:\\dir
z:/dir
z://dir
But I never get success?
Any idea?
thx
I solved it by changing some stuff in the registry of the server as explained in the last answer of this discussion:
http://bugs.php.net/bug.php?id=25805
Thanks to VolkerK and Gumbo anyway!
I love stackoverflow and their great people who help you so incredibly fast!!
EDIT (taken from php.net):
The service has limited access to network resources, such as shares
and pipes, because it has no credentials and must connect using a null
session. The following registry key contains the NullSessionPipes and
NullSessionShares values, which are used to specify the pipes and
shares to which null sessions may connect:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters
Alternatively, you could add the REG_DWORD value
RestrictNullSessAccess to the key and set it to 0 to allow all null
sessions to access all pipes and shares created on that machine.`
add RestrictNullSessAccess=0 to your registery.
You probably let xampp install apache as service and run the php scripts trough this apache. And the apache service (running as localsystem) is not allowed to access the network the way your user account is.
A service that runs in the context of the LocalSystem account inherits the security context of the SCM. The user SID is created from the SECURITY_LOCAL_SYSTEM_RID value. The account is not associated with any logged-on user account.
This has several implications:
...
* The service presents the computer's credentials to remote servers.
...
You can test this by starting the apache as console application (apache_start.bat in the xampp directory should do that) and run the script again. You can use both forward and backward slashes in the unc path. I'd suggest using //server/share since php doesn't care about / in string literals.
<?php
$uncpath = '//server/dir';
$dh = opendir($uncpath);
echo "<pre>\n";
var_dump($dh, error_get_last());
echo "\n</pre>";
Try the file: URI scheme:
file://server/dir
file:///Z:/dir
The begin is always file://. The next path segment is the server. If it’s on your local machine, leave it blank (see second example). See also File URIs in Windows.
Yes, I know this is an old post, but I still found it, and if anyone else does...
On Windows, with newer servers, verify the SMB is installed and enabled on the target machine.

Categories