I'm trying a simple example
$sftp = new phpseclib\Net\SFTP(FTP_ADDRESS);
if (!$sftp->login(FTP_USER, FTP_PASS)) {
$logger->error("FTP credentials error");
$logger->error($sftp->getLastSFTPError());
} else {
$logger->log("Connection successful");
}
print_r($sftp->rawlist());
However the script just hangs and finally times out
( ! ) Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\XookCatalogFeed\lib\phpseclib\Net\SSH2.php on line 3186
Call Stack
# Time Memory Function Location
1 0.2015 152184 {main}( ) ..\index.php:0
2 0.2244 2275600 handle ( ) ..\index.php:95
3 0.2246 2276880 {closure:C:\xampp\htdocs\XookCatalogFeed\handlers\import.php:157-285}( ) ..\index.php:95
4 0.2254 2303944 phpseclib\Net\SFTP->login( ) ..\import.php:170
5 5.1277 4457272 phpseclib\Net\SFTP->_send_sftp_packet( ) ..\SFTP.php:444
6 5.1278 4457592 phpseclib\Net\SSH2->_send_channel_packet( ) ..\SFTP.php:2635
7 30.0009 4457760 phpseclib\Net\SSH2->_send_binary_packet( ) ..\SSH2.php:3332
I have tried a lot of stuff but nothing seems to work. I have done some debugging (step by step) it looks like the servers accepts thje credential but then the client just loops sending empty data at _send_binary_packet.
Here is the log: https://gist.github.com/vlopez/2a48d261ab7713dbc06d
Someone, please help.
Related
I wrote a custom WordPress plugin that creates a cron job that once a day calls the StoreRocket API to grab all the locations. Since there are more than 2000 entries, and their API has a 60 api call per min rate limit each get all location only gives me 15 entries per page, I had to call the api almost 150 times with a 1 second sleep(1) after each API call.
while ( $current_page <= $page_count ) {
set_time_limit(0);
$current_page_url = $storerocket_api_url . "?page=" . $current_page;
$storerocket_get_request = wp_remote_get( $current_page_url, $request_args );
if ( is_wp_error( $storerocket_post_request ) ) {
$log = "ERROR\n" ;
$log .= $storerocket_post_request->get_error_message();
storerocket_log($log);
}
$get_response_body = $storerocket_get_request['body'];
$storerocket_location_data = json_decode( $get_response_body );
$current_page = $storerocket_location_data->meta->current_page;
array_push( $storerocket_location_array, $storerocket_location_data->data );
storerocket_log( "page " . $current_page );
sleep(1);
$current_page++;
}
It all works on my local testing. But when I deployed the plugin to the live server hosted at SiteGround, the cron job stopped at exactly 1 mimute although in the the php_ini the set_time_limit is set at 120. I check the error log, it gives a "Timeout waiting for output from CGI script" at exactly 1 minute after the cron job is called. After some research, I found the Apache Timeout on Siteground is 60 seconds and cannot be changed.
Is there a way to bypass the Apache timeout in code?
I have been running MongoDB in my Amazon since 2019. It has over millions of data and it was working fine until yesterday. But today when I try to query using Laravel jenssegers eloquent model it gives me this error:
Failed to send "count" command with database "<database>": socket error or timeout
at /var/www/html/console/vendor/mongodb/mongodb/src/Operation/Count.php:154
150| if (isset($this->options['readConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) {
151| throw UnsupportedException::readConcernNotSupported();
152| }
153|
154| $cursor = $server->executeReadCommand($this->databaseName, new Command($this->createCommandDocument()), $this->createOptions());
155| $result = current($cursor->toArray());
156|
157| // Older server versions may return a float
158| if ( ! isset($result->n) || ! (is_integer($result->n) || is_float($result->n))) {
Exception trace:
1 MongoDB\Driver\Server::executeReadCommand("dddb", Object(MongoDB\Driver\Command), [Object(MongoDB\Driver\ReadPreference)])
/var/www/html/console/vendor/mongodb/mongodb/src/Operation/Count.php:154
2 MongoDB\Operation\Count::execute(Object(MongoDB\Driver\Server))
/var/www/html/console/vendor/mongodb/mongodb/src/Collection.php:277
Please use the argument -v to see more details.
Fatal error: Maximum execution time of 300 seconds exceeded in htdocs/wp-includes/functions.php on line 4758
I have this error, and the line 4758, that are the function "wp_debug_backtrace_summary". And there another error in:
htdocs/wp-includes/plugin.php
at the line 520-525-575 what is the wordpress function do_action($tag, $arg = '') .
I triyed this: /while ( is_array($wp_filter[$tag]) && next($wp_filter[$tag]) !== false ); reset the server, and clean the plugins.
What could be the cause?
PS: i searched arround the internet but i don't understand many about wordpress.
Could someone elaborate on the purpose of this code and whether it would function, if so what the outcome would be?
The following is my interpretation of it, please point out where im going wrong.
Firstly, the client.php file; this is storing a name within the $param variable, not quite sure what else its doing... the $response is calling a 'get_message' which im guessing is being stored on the server.php file?
server.php is now creating the get_message function based on what was entered from your_name? it then provides a result of a message including your name...
Sorry if this is wrong, im quite new to this and a brief overview of what is happening would greatly help the overall understanding of it.
client.php
<?php
2 require_once (’lib/nusoap.php’);
3 $param = array( ’your_name’ => ’BIA Student’);
4 $client = new nusoap_client(’http://localhost/WebServiceSOAP/server.php’);
5 $response = $client->call(’get_message’,$param);
6 if($client->fault)
7 {
8 echo "FAULT: <p>Code: (".$client->faultcode."</p>";
9 echo "String: ".$client->faultstring;
10 }
11 else
12 {
13 echo $response;
14 }
15 ?>
server.php
1 <?php
2 require_once (’lib/nusoap.php’);
3 $server = new soap_server;
4 $server->register(’get_message’);
5 function get_message($your_name)
6 {
7 if(!$your_name){
8 return new soap_fault(’Client’,’’,’Put Your Name!’);
9 }
10 $result = "Welcome ".$your_name .". Thanks for calling your
11 first Web Service using PHP with SOAP!";
12 return $result;
13 }
14 if ( !isset( $HTTP_RAW_POST_DATA ) )
15 $HTTP_RAW_POST_DATA =file_get_contents( ’php://input’ );
16 // create HTTP listener
17 $server->service($HTTP_RAW_POST_DATA);
18 exit();
19 ?>
The client.php will create a soap connection to a web service. That client.php then queries that web service to see if a fault has occurred, if it does it displays the fault.
The server.php will responds to the client connection with a fault if no name has been set. If a name has been set, it returns a message however saying welcome and creates a listener.
I have a php script that interacts with the google weather api.Everything works ok, but if I test it with a false location like "blahblah" I get a slew of errors in the browser despite having some validation in my script. The php code is as follows:
<?php
function googleWeather($location){
$url = "http://www.google.com/ig/api?weather=" . urlencode($location);
$xml = simplexml_load_file($url);
$current_conditions = $xml->xpath("/xml_api_reply/weather/current_conditions");
$temp_c = $current_conditions[0]->temp_c['data'];
$temp_f = $current_conditions[0]->temp_f['data'];
$result = sprintf("Current temperature is %s° Celsius %s° Fahrenheit",$temp_c,$temp_f);
return $result;
}
$loc = "blahblah";
$goog = googleWeather($loc);
if($goog == false){
echo "An error occurred";
}
else{
echo $goog;
}
?>
The error that is rendered in the browser is as follows:
( ! ) Notice: Undefined offset: 0 in C:\wamp2\www\phpAcademy\GoogleWeatherApi\TMP5c2a1z4emd.php on line 11
Call Stack
# Time Memory Function Location
1 0.1086 370080 {main}( ) ..\TMP5c2a1z4emd.php:0
2 0.1086 370184 googleWeather( ) ..\TMP5c2a1z4emd.php:23
( ! ) Notice: Trying to get property of non-object in C:\wamp2\www\phpAcademy\GoogleWeatherApi\TMP5c2a1z4emd.php on line 11
Call Stack
# Time Memory Function Location
1 0.1086 370080 {main}( ) ..\TMP5c2a1z4emd.php:0
2 0.1086 370184 googleWeather( ) ..\TMP5c2a1z4emd.php:23
( ! ) Notice: Undefined offset: 0 in C:\wamp2\www\phpAcademy\GoogleWeatherApi\TMP5c2a1z4emd.php on line 12
Call Stack
# Time Memory Function Location
1 0.1086 370080 {main}( ) ..\TMP5c2a1z4emd.php:0
2 0.1086 370184 googleWeather( ) ..\TMP5c2a1z4emd.php:23
( ! ) Notice: Trying to get property of non-object in C:\wamp2\www\phpAcademy\GoogleWeatherApi\TMP5c2a1z4emd.php on line 12
Call Stack
# Time Memory Function Location
1 0.1086 370080 {main}( ) ..\TMP5c2a1z4emd.php:0
2 0.1086 370184 googleWeather( ) ..\TMP5c2a1z4emd.php:23
Google returns the following for an invalid location
<xml_api_reply version="1"><weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0"><problem_cause data=""/></weather></xml_api_reply>
This xml doesnt have the element "current_conditions" inside "weather". Thats casusing the error.
Check if exists then proceed which can be done with some thing like
if($current_conditions){
// you code here
} else {
return false;
}
I replaced blahblah with real city and it started to work.
Probably you enter your city address with wrong syntax.
Try to change your location, for example Zurich
The errors are pretty self-explanatory, $current_conditions doesn't contain what you think it does:
$current_conditions = $xml->xpath("/xml_api_reply/weather/current_conditions");
$temp_c = $current_conditions[0]->temp_c['data'];
// ^^^ undefined index
$temp_f = $current_conditions[0]->temp_f['data'];
// ^^^ Trying to access property of non object
You are not validating the result of $current_conditions:
if (is_array($current_conditions) && isset($current_conditions[0]))
{
$temp_c = $current_conditions[0]->temp_c['data'];
$temp_f = $current_conditions[0]->temp_f['data'];
}
Furthermore, you may need to validate the existence of the object properties, as well as the existence of the data key in those properties:
if (is_array($current_conditions) && isset($current_conditions[0]))
{
$cur = $current_conditions[0];
if (isset($cur->temp_c) && isset($cur->temp_c['data']))
{
$temp_c = $cur->temp_c['data'];
}
if (isset($cur->temp_f) && isset($cur->temp_f['data']))
{
$temp_f = $cur->temp_f['data'];
}
}
This is quite verbose, but to be absolutely sure to avoid these notices - it's what you have to do. You can and should turn off error reporting once you go live with your application. Notices are meant to help you debug code, if you understand how they're being generated and can safely ignore them, it may be OK.
And, if you feel confident that you know the API will return FALSE for an invalid query, just check if $current_conditions === FALSE and you can skip all the extra validation.