call dll file in php using com function - php

$stack = new COM("dfs_dll.dll", "dfs_dll.Class1");
$stack->Push(".Net");
$stack->Push("Hello ");
echo $stack->Pop() . $stack->Pop();
Uncaught com_exception: Failed to create COM object `dfs_dll.dll': Invalid syntax

Related

Php-fpm still logging my error even when using catch

Php-fpm error log file is still logging my error even using try-catch
$NUM_OF_ATTEMPTS = 100;
$attempts = 0;
do
{
try
{
$db = new SQLite3('proxies/socks5.db');
$results = $db->query('SELECT proxy FROM socks5proxies WHERE timeout <= ' . $settimeout . $countryq . ';');
while ($row = $results->fetchArray())
{
echo $row['proxy'] . "\r\n";
}
}
catch(Exception $e)
{
$attempts++;
sleep(1);
continue;
}
break;
}
while ($attempts < $NUM_OF_ATTEMPTS);
Expected result:
Retry on error, and don't log the error
Actual results:
Logs the error in the php-fpm error log file:
thrown in /var/www/html/api.php on line 200
[10-Jan-2019 14:00:49 UTC] PHP Warning: SQLite3::query(): Unable to prepare statement: 11, database disk image is malformed in /var/www/html/api.php on line 140
[10-Jan-2019 14:00:49 UTC] PHP Fatal error: Uncaught Error: Call to a member function fetchArray() on boolean in /var/www/html/api.php:141
Stack trace:
#0 {main}
thrown in /var/www/html/api.php on line 141
Call SQLite3::enableExceptions to tell PHP it should throw exceptions instead of standard errors:
try {
$db = new SQLite3('proxies/socks5.db');
$db->enableExceptions(true);
$results = $db->query('...');
} catch (\Exception $e) {
}
In any case, if you need to do 100 attempts to get this to work, then this really isn't the angle you should be taking to fix it.

Unable to Get Documents from a Nested Collection with Cloud Firestore using PHP

Following Google's official documentation at https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/firestore/src/get_all_docs.php, I am unable to retrieve documents that are part of a nested collection, i.e.:
$db = new FirestoreClient([
'projectId' => $projectId,
]);
//$citiesRef = $db->collection('cities'); //working original example
$citiesRef = $db->collection('countries')->document('USA')->collection('cities'); //this throws an HTTP Error 500
$documents = $citiesRef->documents();
foreach ($documents as $document) {
if ($document->exists()) {
printf('Document data for document %s:' . PHP_EOL, $document->id());
print_r($document->fields());
printf(PHP_EOL);
} else {
printf('Document %s does not exist!' . PHP_EOL, $snapshot->id());
}
}
The above code throws an HTTP Error 500. Here is my example database:
The error log (CentOS 6) shows:
[06-May-2018 22:24:26 UTC] PHP Warning: Module 'protobuf' already loaded in Unknown on line 0
[06-May-2018 22:24:26 UTC] PHP Warning: Module 'protobuf' already loaded in Unknown on line 0
[06-May-2018 22:24:27 UTC] PHP Fatal error: Call to undefined method Google\Protobuf\Timestamp::getFields() in /home/user/public_html/my/vendor/google/gax/src/ApiCore/Serializer.php on line 222
[06-May-2018 22:25:02 UTC] PHP Warning: Module 'protobuf' already loaded in Unknown on line 0
[06-May-2018 22:25:02 UTC] PHP Warning: Module 'protobuf' already loaded in Unknown on line 0
I'm aware that Firestore is still in beta. Is this one of the known issues/limitations?
As a workaround, I am able to get the data from the nested document like so:
$db = new FirestoreClient([
'projectId' => $projectId,
]);
//$citiesRef = $db->collection('cities'); //working original example
$citiesRef = $db->collection('countries')->document('USA')->collection('cities');
$documents = $citiesRef->select(['capital','country','name','population','state'])->documents();
foreach ($documents as $document) {
if ($document->exists()) {
printf('Document data for document %s:' . PHP_EOL, $document->id());
//print_r($document->fields()); //this no longer works
print_r($document->data());
printf(PHP_EOL);
} else {
printf('Document %s does not exist!' . PHP_EOL, $snapshot->id());
}
}

How do I include PHP required libs in an AWS EMR streaming cluster

I've created a PHP project that converts JSON format into AVRO format.
The original project requires PHP libs that I'm not sure how to add on EMR.
This is the stderr log received by EMR:
PHP Warning: require_once(vendor/autoload.php): failed to open stream: No such file or directory in /mnt/var/lib/hadoop/tmp/nm-local-dir/usercache/hadoop/filecache/12/convert-json-to-avro.php on line 3
PHP Fatal error: require_once(): Failed opening required 'vendor/autoload.php' (include_path='.:/usr/share/pear:/usr/share/php') in /mnt/var/lib/hadoop/tmp/nm-local- dir/usercache/hadoop/filecache/12/convert-json-to-avro.php on line 3
log4j:WARN No appenders could be found for logger (amazon.emr.metrics.MetricsUtil).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
And here is the main code for the mapper:
#!/usr/bin/php
<?php
require_once 'vendor/autoload.php';
error_reporting(E_ALL);
ini_set('display_errors', 1);
$outputFile = __DIR__ . '/test_avro_out.avr';
$avroJsonSchema = file_get_contents(__DIR__ . '/HttpRequestEvent.avsc');
// Open $file_name for writing, using the given writer's schema
$avroWriter = AvroDataIO::open_file($outputFile, 'w', $avroJsonSchema);
$counter = 1;
while (($buf = fgets(STDIN)) !== false) {
try {
//replace ,null: with ,"null": to prevent map keys which are not strings.
$original = array("null:","userIp");
$replaceWith = array("\"null\":", "userIP");
$data = json_decode(str_replace($original, $replaceWith, $buf), true);
//print_r($buf);
if ($data === false || $data == null ) {
throw new InvalidArgumentException("Unable to parse JSON line");
}
$mapped = map_request_event($data);
var_dump($mapped);
//$avroWriter->append($mapped);
//echo json_encode($mapped), "\n";
} catch (Exception $ex) {
fprintf(STDERR, "Caught exception: %s\n", $ex->getMessage());
fprintf(STDERR, "Line num: %s\n",$counter);
fprintf(STDERR, "buf: %s\n", $buf);
}
$counter++;
}
$avroWriter->close();
Notice I'm using the require_once 'vendor/autoload.php'; which states that autoload.php is under the folder vendor.
What is the right way to load the vendor folder into the EMR cluster (there are needed files there)?
Should the require_once path change?
Thanks.
Following Guy's comment I've used a bash script similar to the one you can find here.
I've changed the require_once 'vendor/autoload.php' line in the code to point to the location where i dropped my files. (/home/hadoop/contents worked perfect).
lastly I've added an EMR bootstrap custom step where you can add the bash script so it can run before the PHP streaming step.

how to over come "Failed to create COM object `word.application': Invalid syntax" when instanciated COM....?

I am trying to convert a word document to text and I use below code for it:
public function executeManoj() {
$filename='C:\xampp\htdocs\branch.com\web\greenwich-beer-and-jazz-application-form.doc';
$TXTfilename = $filename . ".txt";
$word = new COM("word.application") or die("Unable to instantiate Word object");
$word->Documents->Open($filename);
// the '2' parameter specifies saving in txt format
$word->Documents[1]->SaveAs($TXTfilename ,2);
$word->Documents[1]->Close(false);
$word->Quit();
$word->Release();
$word = NULL;
unset($word);
$content = file_get_contents($TXTfilename);
//unlink($TXTfilename);
exit;
}
But it is resulting in error saying
"Failed to create COM object `word.application': Invalid syntax"....
I have set 'Allow service to interact with the desktop' in xammp ticked.
Do I need to install any software before it?
Regarding this PHP bug, it seems that word.application isn't installed on your machine. Try to install it first (don't know where to find it ...).

php: simplexml_load_file check server status

i load file from server:
$url = 'http://www.sample.com/test.xml';
$xml = simplexml_load_file($url);
And if servers is close i get error:
Warning: simplexml_load_file() [function.simplexml-load-file]: php_network_getaddresses: getaddrinfo failed:...
Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity
how to check if the file is reached?
From the manual page for simplexml_load_file
Returns an object of class SimpleXMLElement with properties containing the data held within the XML document. On errors, it will return FALSE.
which means you can do
$url = 'http://www.sample.com/test.xml';
$xml = simplexml_load_file($url);
// check what was returned
if(FALSE === $xml) {
echo 'could not open file';
}

Categories