I'm creating a php script that connects to a 3G modem connected via serial connection on COM5.
I'm getting the following error and I believe it is because php does not have r/w access to COM5:
Warning: fopen(COM5:) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\SMStest\test2.php on line 9
// mode com1: BAUD=9600 PARITY=N data=8 stop=1 xon=off
$fp = fopen ("COM5:", "w+");
if (!$fp) {
echo "Uh-oh. Port not opened.";
} else {
$e = chr(27);
$string = $e . "A" . $e . "H300";
$string .= $e . "V100" . $e . "XL1SATO";
$string .= $e . "Q1" . $e . "Z";
echo $string;
fputs ($fp, $string );
fclose ($fp);
}
There are many ways to access COM ports on windows, alternatives to your method are opening it with the following paths:
\Device\00000123 (You can find the correct value in device manager, properties, details, physical device object name)
\\.\com5 (This is how I would open the port as a file if I was writing a program in C or something)
Related
I have a very small script inwhich I'm trying to get it to post a command in IRC.
<?php
set_time_limit(0);
$socket = fsockopen("irc.twitch.tv", 6667);
fputs($socket,"USER greatbritishbgbot\n");
fputs($socket,"PASS oauth:95uf89rv74gawp93ilfafeqnihpxb74\n");
fputs($socket,"NICK greatbritishbgbot\n");
fputs($socket,"JOIN #greatbritishbg\n");
$ircChannel = "#greatbritishbg";
while($data = fgets($socket, 128)) {
$msg = "test";
fwrite($socket, "PRIVMSG " . $ircChannel . " :" . $msg . "\n");
echo nl2br($data);
flush();
}
?>
Every time I execute this, I receive the error: greatbritishbgbot HELP:Unknown command.
What is the correct way of using fputs to run an IRC command?
Edit: This question was requested to be closed and downvoted because I am apparently asking for debugging information. Which is incorrect. I have asked for an explanation into how one should use fputs in comparison to how I use it.
I ended up using WildPHP which only needed me to modify a config file.
I highly recommend it.
Hi I am using HANA on one EC2 and using by PHP which is already there in SUSE Linux to fetch the data from other Instance. The same code is working fine when i am trying t fetch data from my local system. But it is not working there neither it is showing any error. Please help. Here is my code:
error_reporting(1);
set_time_limit(0);
$date = date("d/m/Y-h:i:s") . "\n"; //to get today's date and time
$logfile = "file-transfer";
$fpath ="log/";
$filepath = $fpath .$logfile . '-log-' . date('Y-m-d') . '.csv'; //path of error log file
$fh1 = fopen($filepath, 'a'); //opening the error log file
fwrite($fh1, "Process Started#" .$date. "\n");
include('Net/SFTP.php');
include('Crypt/RSA.php');
$key = new Crypt_RSA();
$key->loadKey(file_get_contents('key/private.ppk'));
$local_directory = 'sap/';
$remote_directory = '/var/www/';
$file = 'index.html';
$sftp = new Net_SFTP('ec2-XX-XXX-CCC-XX.ap-southeast-1.compute.amazonaws.com');
if (!$sftp->login('ubuntu', $key)) {
fwrite($fh1, "Login Failed" .$date. "\n");
}
else{
fwrite($fh1, "Login Successful#" .$date. "\n");
}
//$success = $sftp->put($remote_directory . $file,$local_directory . $file,NET_SFTP_LOCAL_FILE);
$success = $sftp->get($remote_directory . $file,$local_directory . $file);
if($success){
fwrite($fh1, "File Transferred Successfully#" .$date. "\n");
}
else{
fwrite($fh1, "Error:" .$date.error_get_last(). "\n");
}
Erroneously when i put wrong host name it throw Login failed message. But When i put the correct host name it is not working.
If you are using VPC for your networks inside AWS you need to open the ports in the Security Group so the EC2 instances in the same security group see and can access each other.
http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_SecurityGroups.html
I wrote a script to pull a server list from the master server from Enemy Territory; However it silently fails; I had it working; but for some unknown reason it doesn't anymore.
I used this document to "talk" with the server : http://src.gnu-darwin.org/ports/games/masterserver/work/masterserver-0.4.1/docs/PROTOCOLS
This seems valid since it worked before and it still works on game servers; This is my code :
<?php
// set sv_master1 "etmaster.idsoftware.com"
// set sv_master2 "master0.gamespy.com"
// set sv_master3 "wolfmaster.idsoftware.com"
// set sv_master4 "clanservers.net"
// set sv_master5 "master0.etmaster.net" 213.108.29.23
$host = 'etmaster.idsoftware.com';
$port = '27950';
// $status = chr(255) . chr(255) . chr(255) . chr(255) . chr(0x02) . 'getservers' . chr(0x00);
$status = "\xFF\xFF\xFF\xFFgetservers\x00";
$fp = stream_socket_client("udp://" . $host . ":" . $port, $errno, $errstr, 10);
if (!$fp) {
echo "ERROR: " . $errno . $errstr . "<br>\n";
} else {
fwrite($fp, $status);
//stream_set_timeout($fp, 10); // this is for debugging;
$data = fread($fp, 1024);
fclose($fp);
print_r($data);
}
I attempted 60 seconds execution time (its localhost) but it still doesn't work ... any help is appreciated !
When I check the steps (in cli) the longest time is spend on fread(); but $data contains only an empty string;
The error is small; there had to be 5* \xFF tag; and I only used 4.
I am getting a warning.
Warning: fopen(76561197992146126 .txt): failed to open stream:
Invalid argument in C:\wamp\www\Download\t3.php on line 6
For anyone wondering, this is the contents of main.txt below (http://pastebin.com/53chSRRz)
<?php
$APIkey = 'APIKeyHere';
$file = file('C:\wamp\www\Download\main.txt');
foreach ($file as $link) {
$link2 = "http://api.steampowered.com/ITFItems_440/GetPlayerItems/v0001/?key=" . $APIkey . "&SteamID=" . $link . "&format=json";
$downloaded = file_get_contents($link2);
$fh = fopen($link . ".txt", "a"); //or die("can't open file");
fwrite($fh, $downloaded);
}
echo "Finished";
?>
If I replace "fopen($link . ".txt", "a")" with a static file-name it works. But I need $link to be the filename. It is imperative to my setup.
I am running Windows 7 x64 using WAMP 2.2 with PHP 5.4.3
Your link IDs have whitespace in them. Try adding $link = trim($link); before creating $link2.
From a similar question I used this code to debug the failure of opening a file
echo'<pre>';
error_reporting(E_ALL);
ini_set('display_errors', true);
echo 'phpversion: ', phpversion(), "\n";
echo 'uname: ', php_uname("s r"), "\n"; // name/release of the operating system
//echo 'sapi: ', php_sapi(), "\n";
echo $file, file_exists($file) ? ' exists' : ' does not exist', "\n";
echo $file, is_readable($file) ? ' is readable' : ' is NOT readable', "\n";
echo $file, is_writable($file) ? ' is writable' : ' is NOT readable', "\n";
$fp = #fopen($file, 'x');
if (! $fp) {
echo 'last error: ';
var_dump(error_get_last());
}
echo '</pre>
I get this helpful message
D:\data\openid\nonces\4d895d80---2jmj7l5rSw0yVb.vlWAYkK.YBwk-Bk0DdMtjVYDVZi0npvGwNNFSRy0
phpversion: 5.3.1
uname: Windows NT
D:\data\openid\nonces\4d895...FSRy0 exists
D:\data\openid\nonces\4d895...FSRy0 is readable
D:\data\openid\nonces\4d895...FSRy0 is writable
last error: array(4) {
["type"]=>
int(2)
["message"]=>
string(188) "fopen(D:\data\openid\nonces\4d895d80---2jmj7l5rSw0yVb.vlWAYkK.YBwk-Bk0DdMtjVYDVZi0npvGwNNFSRy0) [function.fopen]: failed to open stream: File exists"
["file"]=>
string(38) "D:\web\library\Utils.php"
["line"]=>
int(179)
}
"failed to open stream: File exists" - What could that mean?
This happens because you used the 'x' flag to fopen(). The PHP manual says about it:
'x' Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call.
You probably want to use fopen($file, 'c') or just the ordinary w mode.