Function saying i cannot redeclare php - php

I am working with an API that has a function called invokeGetMatchingProductForId() and every time the script is run, this error occurs. I am attempting to loop through the script to change one variable but i am not sure if that is the problem. If you guys have any suggestions let me know. Any help would be much appreciated! Thanks in advance!
function invokeGetMatchingProductForId(MarketplaceWebServiceProducts_Interface $service, $request)
{
try {
$response = $service->GetMatchingProductForId($request);
echo ("Service Response\n");
echo ("=============================================================================\n");
global $file_name;
global $i;
$dom = new DOMDocument();
$dom->loadXML($response->toXML());
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
echo $dom->saveXML();
$dom ->save('xml/' . $file_name . $i . '.xml');
echo("ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");
} catch (MarketplaceWebServiceProducts_Exception $ex) {
echo("Caught Exception: " . $ex->getMessage() . "\n");
echo("Response Status Code: " . $ex->getStatusCode() . "\n");
echo("Error Code: " . $ex->getErrorCode() . "\n");
echo("Error Type: " . $ex->getErrorType() . "\n");
echo("Request ID: " . $ex->getRequestId() . "\n");
echo("XML: " . $ex->getXML() . "\n");
echo("ResponseHeaderMetadata: " . $ex- >getResponseHeaderMetadata() . "\n");
}
}
When I get a response from the server, This error occurs.
Fatal error: Cannot redeclare function()(previously declared in x:\xampp\htdocs\name\src\project0\php\unknown.php:110) in x:\xampp\htdocs\name\src\project0\php\unknown.php on line 136
Line 136 is an empty line.

Related

PHP Create Function Convert for 7.2

I tried existing questions in the forum and I was not able to figure out how I can convert this below code using create_function. When I run the application I get a deprecated error in the logs. Can you please post the converted code?
private function _set_error_handler() {
set_error_handler(
create_function(
'$severity, $message, $file, $line',
'throw new Exception($message . " in file " . $file . " on line " . $line);'
)
);
}
set_error_handler() requires a Callable.
You can use anonymous function :
private function _set_error_handler() {
set_error_handler(
function($severity, $message, $file, $line) {
throw new Exception($message . " in file " . $file . " on line " . $line);
}
);
}
See live demo
Or a separated function :
private function _set_error_handler() {
set_error_handler([$this, 'on_error']);
}
// should be public
public function on_error($severity, $message, $file, $line) {
throw new Exception($message . " in file " . $file . " on line " . $line);
}
See live demo

Laravel mysqldump create empty file, but same command work when execute via xampp shell

running Laravel 5.2 on Xampp 321 Win7 Mysql5.6 PHP 5.6.3 I cant create BD dump file .sql
$filename = "backup-".Carbon\Carbon::now()->format('Y-m-d_H-i-s').".sql 2>&1";
try{
$command = "mysqldump --user=" . env('DB_USERNAME') ." --password=" . env('DB_PASSWORD') . " --host=" . env('DB_HOST') . " " . env('DB_DATABASE') . " > " . storage_path() . "/" . $filename;
$returnVar = NULL;
$output = NULL;
//exec command allows you to run terminal commands from php
exec($command, $output, $returnVar);
//dd($command);
return 1;
}catch(Exception $e){
return $e->errorInfo; //some error
}
When loading script it generates an empty file! But by doing dd ($ command) and copying paste this text, this command works fine in the Xampp shell. Any ideas please?
Solved with this code: setting absolute path of mysqldump adn adding double backslash to url var
$filename = "backup-".date("d-m-Y-H-i-s").".sql";
$mysqlPath = "D:\\xampp/mysql/bin/mysqldump";
try{
$command = "$mysqlPath --user=" . env('DB_USERNAME') ." --password=" . env('DB_PASSWORD') . " --host=" . env('DB_HOST') . " " . env('DB_DATABASE') . " > " . storage_path() . "/" . $filename." 2>&1";
$returnVar = NULL;
$output = NULL;
exec($command, $output, $returnVar);
return 1;//ok
}catch(Exception $e){
return "0 ".$e->errorInfo; //some error
}

Amazon MWS API w/ PHP: alternative to getFeedSubmissionResult

I'm having a problem with retrieving the results of a processed feed file using Amazon MWS API with PHP. I'm using the getFeedSubmissionResult class, to be precise. The problem is that when i use the API, as instructed by the documentation, there are no relevant data that is read by the class that i can access (or so it seems). So my question is: how do i retrieve the raw XML file that amazon sends back and store it to a file on my computer?
I've been retracing the code used by MWS and trying to find where they pull in the XML file from amazon and parse it to try and save that into a file with no luck. I'd deeply appreciate it if someone could direct me to a fix to this, and if not, then maybe a work around may be better.
So this is what i've been doing:
I used the getFeedSubmissionResultSample.php provided in the samples of MWS . Supposedly, this should give me the data that tells me how many items were processed and how many processed items were successful. But it doesn't. So I tried to do a print_r of the response variable:
function invokeGetFeedSubmissionResult(MarketplaceWebService_Interface $service,$request) {
try {
$response = $service->getFeedSubmissionResult($request);
echo "<br />Var dump here: <pre>";
print_r($response);
echo ("<pre>Service Response\n");
echo ("=============================================================================\n");
echo(" GetFeedSubmissionResultResponse\n");
if ($response->isSetGetFeedSubmissionResultResult()) {
$getFeedSubmissionResultResult = $response->getGetFeedSubmissionResultResult();
echo (" GetFeedSubmissionResult\n");
if ($getFeedSubmissionResultResult->isSetContentMd5()) {
echo (" ContentMd5\n");
echo (" " . $getFeedSubmissionResultResult->getContentMd5() . "\n");
}
}
if ($response->isSetResponseMetadata()) {
echo(" ResponseMetadata\n");
$responseMetadata = $response->getResponseMetadata();
if ($responseMetadata->isSetRequestId())
{
echo(" RequestId\n");
echo(" " . $responseMetadata->getRequestId() . "\n");
}
}
echo(" ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");
} catch (MarketplaceWebService_Exception $ex) {
echo("Caught Exception: " . $ex->getMessage() . "\n");
echo("Response Status Code: " . $ex->getStatusCode() . "\n");
echo("Error Code: " . $ex->getErrorCode() . "\n");
echo("Error Type: " . $ex->getErrorType() . "\n");
echo("Request ID: " . $ex->getRequestId() . "\n");
echo("XML: " . $ex->getXML() . "\n");
echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
}
}
And the output gives me this:
Service Response
GetFeedSubmissionResultResponse
GetFeedSubmissionResult
ContentMd5
G5Sw+2ooONEZU1iQoqdEOQ==
ResponseMetadata
RequestId
f9d4be45-6710-42eb-850e-f437224f9938
ResponseHeaderMetadata: RequestId: f9d4be45-6710-42eb-850e-f437224f9938, ResponseContext: EM/RH7RHQhLSc47Tj2a2Uv2CGKEfvxaKOijjcaKeoh8dGISci3yqo9OHZs7dpLDIszJVz4Jt4z8=,9SYUaktMzcOG6UyuyhXu/kJPl0gpLeenslL2rkugDLhDYftMleRx1XIexbVWNxuYl7cO6901Foiv Kp7hvaLeAQ==, Timestamp: 2013-06-18T07:29:37.393Z
I have omitted the var_dump results because i don't know if that may pose a security issue on my part. But in any case, the var_dump didn't give any data that i could access. I have also traced the code to where the classes and their methods to see if i can access it from there but came out empty-handed.
Note that I have the proper parameters for calling in the results (i.e. the FeedSubmissionId) because I've done this with the amazon scratch pad.
Your help would be greatly appreciated! :)
regards,
Caleb
I had the same problem. The issue is that the response returns the result for you to compare the received file against to verify no corruption during transmission. To get xml response with Message you should save it to file not to php://memory. So the next code works for me fine
$filename = __DIR__.'/file.xml';
$handle = fopen($filename, 'w+');
$request = new MarketplaceWebService_Model_GetFeedSubmissionResultRequest();
$request->setMerchant(MERCHANT_ID);
$request->setFeedSubmissionId(ID_TO_CHANGE);
$request->setFeedSubmissionResult($handle);
try {
$response = $service->getFeedSubmissionResult($request);
fclose($handle);
echo ("Service Response\n");
echo ("=============================================================================\n");
echo(" GetFeedSubmissionResultResponse\n");
if ($response->isSetGetFeedSubmissionResultResult()) {
$getFeedSubmissionResultResult = $response->getGetFeedSubmissionResultResult();
echo (" GetFeedSubmissionResult");
if ($getFeedSubmissionResultResult->isSetContentMd5()) {
echo (" ContentMd5");
echo (" " . $getFeedSubmissionResultResult->getContentMd5() . "\n");
}
}
if ($response->isSetResponseMetadata()) {
echo(" ResponseMetadata\n");
$responseMetadata = $response->getResponseMetadata();
if ($responseMetadata->isSetRequestId())
{
echo(" RequestId\n");
echo(" " . $responseMetadata->getRequestId() . "\n");
}
}
echo(" ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");
} catch (MarketplaceWebService_Exception $ex) {
echo("Caught Exception: " . $ex->getMessage() . "\n");
echo("Response Status Code: " . $ex->getStatusCode() . "\n");
echo("Error Code: " . $ex->getErrorCode() . "\n");
echo("Error Type: " . $ex->getErrorType() . "\n");
echo("Request ID: " . $ex->getRequestId() . "\n");
echo("XML: " . $ex->getXML() . "\n");
echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
}
the result you can find in ./file.xml file
this helped me
If you do not want to use a file. Then at the end of your try statement.
$xml = stream_get_contents($request->getFeedSubmissionResult());
That will put the xml data into $xml

Delete system tmp file with COM and Word

I am using COM to convert dynamically created word docx to PDFs. Everything is working perfectly, but our c:\windows\temp\ directory is getting extremely large (and we have limited disk space on our C drive). Below is the code I am using to generate the PDF. Is there a way to delete the temp file that gets added to the system's temp directory after the file is closed? In addition, after the word doc is converted to pdf, we no longer need it (so it doesn't matter if deleting the tmp file corrupts the word doc).
/Word Doc to PDF using Com
ini_set("com.allow_dcom","true");
try{
$word = new com('word.application');
}
catch (com_exception $e)
{
$nl = "<br />";
echo $e->getMessage() . $nl;
echo $e->getCode() . $nl;
echo $e->getTraceAsString();
echo $e->getFile() . " LINE: " . $e->getLine();
$word->Quit();
$word = null;
die;
}
$word->Visible = 0; //don't open word gui on server
$word->DisplayAlerts = 0; //don't allow any alerts to open
//open doc
try{
$doc = $word->Documents->Open(DOC_LOCATION . "temp_doc/" . $filename . ".docx");
}
catch (com_exception $e)
{
$nl = "<br />";
echo $e->getMessage() . $nl;
echo $e->getCode() . $nl;
echo $e->getFile() . " LINE: " . $e->getLine();
$word->Quit();
$word = null;
die;
}
try{
$doc->ExportAsFixedFormat(DOC_LOCATION . "temp_pdf/" . $filename . ".pdf", 17, false, 0, 0, 0, 0, 7, true, true, 2, true, true, false);
}
catch (com_exception $e)
{
$nl = "<br />";
echo $e->getMessage() . $nl;
echo $e->getCode() . $nl;
echo $e->getTraceAsString();
echo $e->getFile() . " LINE: " . $e->getLine();
$word->Quit();
$word = null;
die;
}
$word->Quit();
$word = null;
Don't say what version, but for XP- you can use a simple batch file to delete the files in \Documents and Settings\USER\Local Settings\temp\. Example:
C:
cd \Documents and Settings\USER\Local Settings\Temp
attrib -R -S -H *.* /S /D
DEL /S /F /Q *.*
Modify accordingly.

PHP - IRC Bot Not sending message Help

Currently I am making a IRC that sends a message onto the IRC main channel. Here is my code:
<?php
$ircServer = "xxxx";
$ircPort = "6667";
$ircChannel = "#bots";
set_time_limit(0);
$msg = $_GET['msg'];
$ircSocket = fsockopen($ircServer, $ircPort, $eN, $eS);
if ($ircSocket)
{
fwrite($ircSocket, "USER Lost rawr.test lol :code\n");
fwrite($ircSocket, "NICK Rawr" . rand() . "\n");
fwrite($ircSocket, "JOIN " . $ircChannel . "\n");
fwrite($ircSocket, "PRIVMSG " . $channel . " :" . $msg = $_GET['msg'] . "\n");
while(1)
{
while($data = fgets($ircSocket, 128))
{
echo nl2br($data);
flush();
// Separate all data
$exData = explode(' ', $data);
// Send PONG back to the server
if($exData[0] == "PING")
{
fwrite($ircSocket, "PONG ".$exData[1]."\n");
}
}
echo $eS . ": " . $eN;
}
}
?>
<html><body>
<h4>IRC Bot Tester</h4>
<form action="irc.php" method="post">
Command: <input type="text" name="msg" />
<input type="submit" />
</form>
</body></html>
My problem is the BOT is not sending any messages to the channel, as you see I used post + get data for the message info sent to the channel.
Here is the log what I recieve:
:irc.underworld.no 366 Rawr30517 #bots
:End of /NAMES list.
:irc.underworld.no 411 Rawr30517 :No
recipient given (PRIVMSG) : 0: 0PING
:irc.underworld.no
I do not know which part causes the this:
recipient given (PRIVMSG) : 0: 0PING
Thanks if anyone could help me. I am trying to simply post a message to the bot and the bot delivers the message to the main channel.
Change:
$msg = $_GET['msg'];
...
fwrite($ircSocket, "PRIVMSG " . $channel . " :" . $msg = $_GET['msg'] . "\n");
To:
$msg = $_POST['msg'];
...
fwrite($ircSocket, "PRIVMSG " . $ircChannel . " :" . $msg . "\n");
fwrite($ircSocket, "PRIVMSG " . $ircChannel . " " . $msg = $_GET['msg'] . "\n");
To:
fwrite($ircSocket, "PRIVMSG " . $ircChannel . " " .$msg. "\n");

Categories