I need to update all media in a larger Shopware shop, with about 10000 products. I use the Shopware php SDK by vienthuong. I download 200 product objects at a time, create an upsert with their cover media id within a while loop.
It all goes well and good for about 2000 products. Then, nothing happens for a while, and then I get a "cURL error 6: Could not resolve host after resolving host before":
Fatal error: Uncaught GuzzleHttp\Exception\ConnectException: cURL error 6: Could not resolve host: foo-shop.de (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://glogner-shop.de/api/oauth/token in /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:210
Stack trace:
#0 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(158): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array)
#1 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(110): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
#2 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php(47): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
#3 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/guzzle/src/RetryMiddleware.php(67): GuzzleHttp\Handler\CurlHandler->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#4 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/guzzle/src/RetryMiddleware.php(114): GuzzleHttp\RetryMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#5 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/guzzle/src/RetryMiddleware.php(106): GuzzleHttp\RetryMiddleware->doRetry(Object(GuzzleHttp\Psr7\Request), Array)
#6 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/promises/src/RejectedPromise.php(42): GuzzleHttp\RetryMiddleware->GuzzleHttp\{closure}(Object(GuzzleHttp\Exception\ConnectException))
#7 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/promises/src/TaskQueue.php(48): GuzzleHttp\Promise\RejectedPromise::GuzzleHttp\Promise\{closure}()
#8 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/promises/src/Promise.php(248): GuzzleHttp\Promise\TaskQueue->run(true)
#9 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/promises/src/Promise.php(224): GuzzleHttp\Promise\Promise->invokeWaitFn()
#10 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/promises/src/Promise.php(269): GuzzleHttp\Promise\Promise->waitIfPending()
#11 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/promises/src/Promise.php(226): GuzzleHttp\Promise\Promise->invokeWaitList()
#12 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/promises/src/Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending()
#13 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/guzzle/src/Client.php(187): GuzzleHttp\Promise\Promise->wait()
#14 /Users/m/Desktop/updater-dev/coverImage/vendor/vin-sw/shopware-sdk/src/Client/Client.php(108): GuzzleHttp\Client->request('POST', 'https://glogner...', Array)
#15 /Users/m/Desktop/updater-dev/coverImage/vendor/vin-sw/shopware-sdk/src/Client/Client.php(135): Vin\ShopwareSdk\Client\Client->request('POST', 'https://glogner...', Array)
#16 /Users/m/Desktop/updater-dev/coverImage/vendor/vin-sw/shopware-sdk/src/Client/AdminAuthenticator.php(56): Vin\ShopwareSdk\Client\Client->post('https://glogner...', Array)
#17 /Users/m/Desktop/updater-dev/coverImage/token.php(15): Vin\ShopwareSdk\Client\AdminAuthenticator->fetchAccessToken()
#18 /Users/m/Desktop/updater-dev/coverImage/main.php(61): require('/Users/miamahnc...')
#19 {main}
thrown in /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 210
So, the error is telling me that it can't get the auth token, which worked fine before.
Code:
$time_pre = microtime(true);
require __DIR__ . '/token.php';
$criteria = new Criteria(1, 200);
$criteria->setTotalCountMode(1);
$criteria->addInclude('product', ["coverId"]);
$page_count = 1;
$total_product_count = 0;
do{
$context = new Context($config['shop_url'], $accessToken);
$syncService = new SyncService($context);
$data = [];
$payload = new SyncPayload();
$productRepository = RepositoryFactory::create(ProductDefinition::ENTITY_NAME);
$products = $productRepository->search($criteria, $context); //EntitySearchResult
$criteria->setPage($page_count);
if(microtime(true) >= $time_pre+(10*50) ){
echo "getting new token! \n";
$time_pre = microtime(true);
require __DIR__ . '/token.php';
$context = new Context($config['shop_url'], $accessToken);
$syncService = new SyncService($context);
}
$total_product_count += $products->count();
foreach( $products->getEntities()->getElements() as $key => $entity){
$ci = $entity->coverId;
if(!is_null($ci)){
$data[] = array('id' => $ci, 'position' => 0);
}
}
$payload->set(ProductMediaDefinition::ENTITY_NAME . '-upsert', new SyncOperator(ProductMediaDefinition::ENTITY_NAME, SyncOperator::UPSERT_OPERATOR,
$data
));
if(microtime(true) >= $time_pre+(10*50) ){
echo "getting new token! \n";
$time_pre = microtime(true);
require __DIR__ . '/token.php';
$context = new Context($config['shop_url'], $accessToken);
$syncService = new SyncService($context);
}
$response = $syncService->sync($payload);
++$page_count;
}while($products->getMeta()->getTotal() - $total_product_count > 0);
It's not that pretty anymore, but I just want it to work first.
Related
After installing Symfony 4.1.3 on a box running SLES 12.3 with PHP 7.1.20 (and later upgraded to 7.1.21), Apache child processes began segmentation faulting. This happens several times per hour seemingly randomly.
[Fri Sep 07 09:57:01.166821 2018] [core:notice] [pid 10004:tid 139775548520192] AH00052: child pid 7164 exit signal Segmentation fault (11)
I cannot discern any particular pattern to the madness, only that it could potentially have something to do with Symfony's interaction with phpenv (based on the dump below).
Background to the purpose of this Symfony install: Used as a general CRUD application with API endpoints which spit out JSON data. I am using "friendsofsymfony/rest-bundle": "^2.3" to handle the API. The API endpoints themselves are pretty straightforward. Here is an example of one:
public function getExternalRedirectAction(Request $request): Response
{
$url = $request->query->get('url');
$redirect = $this->getDoctrine()->getRepository(Redirect::class)->findOneBy(['fromLink' => $url]);
if (!$redirect) {
$response = new Response(json_encode("The redirect you requested was not found."), 404, array('Content-Type' => 'application/json'));
return $response;
}
$redirect->setVisits($redirect->getVisits() + 1);
$redirect->setLastVisit(new \DateTime());
$em = $this->getDoctrine()->getManager();
$em->persist($redirect);
$em->flush();
$context = new SerializationContext();
$context->setSerializeNull(true);
$serializer = $this->container->get('jms_serializer');
$serialized = $serializer->serialize($redirect, 'json', $context);
$response = new Response($serialized, 200, array('Content-Type' => 'application/json'));
return $response;
}
Here is a full backtrace following a seg fault.
(gdb) backtrace full
#0 0x00007fedcc1162b3 in __strchr_sse2 () from /lib64/libc.so.6
No symbol table info available.
#1 0x00007fedcc0cc0c8 in putenv () from /lib64/libc.so.6
No symbol table info available.
#2 0x00007fedc616a85c in php_putenv_destructor (zv=0x7fed96ad59a0)
at /usr/local/src/php-7.1.21/ext/standard/basic_functions.c:3435
pe = 0x7fed96afaa40
#3 0x00007fedc63afc65 in zend_hash_destroy (ht=0x7fed8c0e4328)
at /usr/local/src/php-7.1.21/Zend/zend_hash.c:1246
p = 0x7fed96ad59a0
end = 0x7fed96ad5a80
#4 0x00007fedc616c467 in zm_deactivate_basic (type=1, module_number=33)
at /usr/local/src/php-7.1.21/ext/standard/basic_functions.c:3811
No locals.
#5 0x00007fedc63a43ad in zend_deactivate_modules ()
at /usr/local/src/php-7.1.21/Zend/zend_API.c:2576
module = 0xdfd070
p = 0xf85808
__orig_bailout = 0x0
__bailout = {{__jmpbuf = {140658233296848, 1066617060162552172,
140658502012712, 140659038370920, 140659038370104,
140659038370752, 1066617060149969260, 1066664924020097388},
__mask_was_saved = 0, __saved_mask = {__val = {
---Type <return> to continue, or q <return> to quit---
1066664949417394540, 140655883976704, 140659220598624,
15867216, 18446744064156967775, 15866640, 77753426461,
140658845055312, 140659209739746, 140658845055344,
140658233298472, 140658845055344, 0, 140658845055328,
140659209527934, 0}}}}
#6 0x00007fedc62d8638 in php_request_shutdown (dummy=0x0)
at /usr/local/src/php-7.1.21/main/main.c:1876
report_memleaks = 1 '\001'
#7 0x00007fedc648d467 in php_apache_request_dtor (r=0x7fed9c0c0f28)
at /usr/local/src/php-7.1.21/sapi/apache2handler/sapi_apache2.c:552
No locals.
#8 0x00007fedc648df8a in php_handler (r=0x7fed9c0c0f28)
at /usr/local/src/php-7.1.21/sapi/apache2handler/sapi_apache2.c:724
ctx = 0x7fed781b6810
conf = 0xd82a70
brigade = 0x7fed9c195330
bucket = 0xdcba00
rv = 0
parent_req = 0x0
#9 0x0000000000455850 in ap_run_handler (r=r#entry=0x7fed9c0c0f28)
at config.c:170
pHook = <optimized out>
n = 5
---Type <return> to continue, or q <return> to quit---
rv = -1
#10 0x0000000000455d99 in ap_invoke_handler (r=r#entry=0x7fed9c0c0f28)
at config.c:444
handler = <optimized out>
p = <optimized out>
result = <optimized out>
old_handler = 0x0
ignore = <optimized out>
#11 0x000000000046aa4c in ap_internal_redirect (new_uri=<optimized out>,
r=<optimized out>) at http_request.c:791
access_status = <optimized out>
new = 0x7fed9c0c0f28
#12 0x00007fedc701d25c in handler_redirect (r=0x7fed9c0c2800)
at mod_rewrite.c:5256
No locals.
#13 0x0000000000455850 in ap_run_handler (r=r#entry=0x7fed9c0c2800)
at config.c:170
pHook = <optimized out>
n = 4
rv = -1
#14 0x0000000000455d99 in ap_invoke_handler (r=r#entry=0x7fed9c0c2800)
at config.c:444
handler = <optimized out>
---Type <return> to continue, or q <return> to quit---
p = <optimized out>
result = <optimized out>
old_handler = 0x7fedc7025e14 "redirect-handler"
ignore = <optimized out>
#15 0x000000000046b6da in ap_process_async_request (r=0x7fed9c0c2800)
at http_request.c:453
access_status = 0
#16 0x0000000000467c51 in ap_process_http_async_connection (c=0x7fedbc043c68)
at http_core.c:154
r = 0x7fed9c0c2800
cs = 0x7fedbc043c30
#17 ap_process_http_connection (c=0x7fedbc043c68) at http_core.c:248
No locals.
#18 0x000000000045f380 in ap_run_process_connection (c=c#entry=0x7fedbc043c68)
at connection.c:42
pHook = <optimized out>
n = 2
rv = -1
#19 0x0000000000472dca in process_socket (thd=<optimized out>,
p=<optimized out>, sock=<optimized out>, cs=0x7fedbc043bc0,
my_child_num=<optimized out>, my_thread_num=<optimized out>)
at event.c:1048
c = 0x7fedbc043c68
---Type <return> to continue, or q <return> to quit---
conn_id = <optimized out>
clogging = <optimized out>
rv = <optimized out>
rc = 0
#20 0x0000000000474348 in worker_thread (thd=0xd23a78, dummy=<optimized out>)
at event.c:2122
csd = 0x7fedbc0439c0
cs = 0x0
te = 0x0
ptrans = 0x7fedbc043938
ti = <optimized out>
process_slot = 3
thread_slot = 24
rv = <optimized out>
is_idle = 0
#21 0x00007fedcc646724 in start_thread () from /lib64/libpthread.so.0
No symbol table info available.
#22 0x00007fedcc181e8d in clone () from /lib64/libc.so.6
No symbol table info available.
Not sure if this is the cause of the segmentation fault but, Symfony 4.0 (and above) requires PHP 7.1.3 or higher to run, in addition to other minor requirements, according to the docs.
This turned out to be an issue of colliding child processes between mod_ssl and mod_php. After lots of experimentation, we ended up sending all incoming requests into mod_ssl to php_fpm. We also set up opcache and swapped out the default openssl version on our box with openssl v1.1.0.
$transport = Swift_SendmailTransport::newInstance();
$mailer = \Swift_Mailer::newInstance($transport);
$message = \Swift_Message::newInstance();
$message->setSubject('Email From Our Website');
$message->setFrom(array(
$cleanEmail => $cleanName
));
$message->setTo(array('talhagillani96#gmail.com'));
$message->setBody($cleanMessage);
$result = $mailer->send($message);
if($result > 0) {
$app->flash('success', 'Thanks So Much! You are AWESOME!!!');
$app->redirect('/');
} else {
$app->flash('fail', 'So Sorry, Something Went Wrong.Try Again!');
// log that there was an error
$app->redirect('/contact');
}
Slim Application Error The application could not run because of the following error:
Details Type: Swift_TransportException Message: Process could not be started [The system cannot find the path specified. ]
File: C:\xampp\htdocs\Projects\php2015\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php Line: 294 Trace #0 C:\xampp\htdocs\Projects\php2015\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php(58): Swift_Transport_StreamBuffer->_establishProcessConnection() #1 C:\xampp\htdocs\Projects\php2015\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php(113): Swift_Transport_StreamBuffer->initialize(Array) #2 C:\xampp\htdocs\Projects\php2015\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\SendmailTransport.php(51): Swift_Transport_AbstractSmtpTransport->start() #3 C:\xampp\htdocs\Projects\php2015\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Mailer.php(79): Swift_Transport_SendmailTransport->start() #4 C:\xampp\htdocs\Projects\php2015\index.php(41): Swift_Mailer->send(Object(Swift_Message)) #5 [internal function]: {closure}() #6 C:\xampp\htdocs\Projects\php2015\vendor\slim\slim\Slim\Route.php(468): call_user_func_array(Object(Closure), Array) #7 C:\xampp\htdocs\Projects\php2015\vendor\slim\slim\Slim\Slim.php(1357): Slim\Route->dispatch() #8 C:\xampp\htdocs\Projects\php2015\vendor\slim\slim\Slim\Middleware\Flash.php(85): Slim\Slim->call() #9 C:\xampp\htdocs\Projects\php2015\vendor\slim\slim\Slim\Middleware\MethodOverride.php(92): Slim\Middleware\Flash->call() #10 C:\xampp\htdocs\Projects\php2015\vendor\slim\slim\Slim\Middleware\SessionCookie.php(110): Slim\Middleware\MethodOverride->call() #11 C:\xampp\htdocs\Projects\php2015\vendor\slim\slim\Slim\Middleware\PrettyExceptions.php(67): Slim\Middleware\SessionCookie->call() #12 C:\xampp\htdocs\Projects\php2015\vendor\slim\slim\Slim\Slim.php(1302): Slim\Middleware\PrettyExceptions->call() #13 C:\xampp\htdocs\Projects\php2015\index.php(53): Slim\Slim->run() #14 {main}
Based on this answer:
Use
$transport = Swift_MailTransport::newInstance();
instead of Swift_SendmailTransport.
I'm running a console process that listens for an event and writes a . to the console to indicate progress. This can run for 10-15 minutes, but by about 10 min I get the following series of fatal console errors:
[2014-10-14 11:13:49] local.ERROR: 500 - fopen(php://stderr): failed to open stream: operation failed # /
exception 'ErrorException' with message 'fopen(php://stderr): failed to open stream: operation failed' in /vagrant/www/test.dev/laravel/vendor/symfony/console/Symfony/Component/Console/Output/ConsoleOutput.php:53
Stack trace:
#0 [internal function]: Illuminate\Exception\Handler->handleError(2, 'fopen(php://std...', '/vagrant/www/te...', 53, Array)
#1 /vagrant/www/test.dev/laravel/vendor/symfony/console/Symfony/Component/Console/Output/ConsoleOutput.php(53): fopen('php://stderr', 'w')
#2 /vagrant/www/test.dev/laravel/app/library/ecomevo/task/src/eComEvo/TaskRunner/Traits/Events.php(262): Symfony\Component\Console\Output\ConsoleOutput->__construct()
#3 [internal function]: eComEvo\TaskRunner\TaskRunner::eComEvo\TaskRunner\Traits\{closure}('.', 280, Array)
#4 /vagrant/www/test.dev/laravel/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(199): call_user_func_array(Object(Closure), Array)
#5 /vagrant/www/test.dev/laravel/app/library/ecomevo/task/vendor/illuminate/support/Illuminate/Support/Facades/Facade.php(211): Illuminate\Events\Dispatcher->fire('task.group.prog...', Array)
#6 /vagrant/www/test.dev/laravel/app/library/ecomevo/task/src/eComEvo/TaskRunner/Traits/Events.php(92): Illuminate\Support\Facades\Facade::__callStatic('fire', Array)
#7 /vagrant/www/test.dev/laravel/app/library/ecomevo/task/src/eComEvo/TaskRunner/Traits/Events.php(92): Illuminate\Support\Facades\Event::fire('task.group.prog...', Array)
#8 /vagrant/www/test.dev/laravel/app/library/ecomevo/task/src/eComEvo/TaskRunner/Traits/Events.php(205): eComEvo\TaskRunner\TaskRunner::event('progress', '.', 280, '423403-23463321-604...', 'event')
#9 /vagrant/www/test.dev/laravel/app/models/TaskRunner.php(280): eComEvo\TaskRunner\TaskRunner::progress('.', 280, '2423-521354...')
#10 /vagrant/www/test.dev/laravel/app/library/ecomevo/task/src/eComEvo/TaskRunner/Commands/TaskRunnerImportOrdersCommand.php(128): TaskRunner::import('15', NULL, Array, '16', '4')
#11 /vagrant/www/test.dev/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php(112): eComEvo\TaskRunner\Commands\TaskRunnerImportOrdersCommand->fire()
#12 /vagrant/www/test.dev/laravel/vendor/symfony/console/Symfony/Component/Console/Command/Command.php(252): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /vagrant/www/test.dev/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php(100): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /vagrant/www/test.dev/laravel/vendor/symfony/console/Symfony/Component/Console/Application.php(889): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /vagrant/www/test.dev/laravel/vendor/symfony/console/Symfony/Component/Console/Application.php(193): Symfony\Component\Console\Application->doRunCommand(Object(eComEvo\TaskRunner\Commands\TaskRunnerImportOrdersCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /vagrant/www/test.dev/laravel/vendor/symfony/console/Symfony/Component/Console/Application.php(124): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /vagrant/www/test.dev/laravel/artisan(59): Symfony\Component\Console\Application->run()
#18 {main} [] []
[2014-10-14 11:13:50] local.ERROR: 500 - proc_open(): unable to create pipe Too many open files # /
exception 'ErrorException' with message 'proc_open(): unable to create pipe Too many open files' in /vagrant/www/test.dev/laravel/vendor/symfony/console/Symfony/Component/Console/Application.php:983
Stack trace:
#0 [internal function]: Illuminate\Exception\Handler->handleError(2, 'proc_open(): un...', '/vagrant/www/te...', 983, Array)
#1 /vagrant/www/test.dev/laravel/vendor/symfony/console/Symfony/Component/Console/Application.php(983): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 /vagrant/www/test.dev/laravel/vendor/symfony/console/Symfony/Component/Console/Application.php(799): Symfony\Component\Console\Application->getSttyColumns()
#3 /vagrant/www/test.dev/laravel/vendor/symfony/console/Symfony/Component/Console/Application.php(760): Symfony\Component\Console\Application->getTerminalDimensions()
#4 /vagrant/www/test.dev/laravel/vendor/symfony/console/Symfony/Component/Console/Application.php(690): Symfony\Component\Console\Application->getTerminalWidth()
#5 /vagrant/www/test.dev/laravel/vendor/laravel/framework/src/Illuminate/Console/Application.php(201): Symfony\Component\Console\Application->renderException(Object(ErrorException), Object(Symfony\Component\Console\Output\StreamOutput))
#6 /vagrant/www/test.dev/laravel/vendor/symfony/console/Symfony/Component/Console/Application.php(131): Illuminate\Console\Application->renderException(Object(ErrorException), Object(Symfony\Component\Console\Output\StreamOutput))
#7 /vagrant/www/test.dev/laravel/artisan(59): Symfony\Component\Console\Application->run()
#8 {main} [] []
Here is the code that is triggering these errors after 10 min:
static::listen(
'progress',
function ($indicator = '.', $line = null, $id = 0) {
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
$extra = [];
if (static::$debug > 2) {
if (!empty($line) && $line !== true)
$extra[] = "line=$line";
if (!empty($id)) {
if (is_array($id))
$id = implode(',', $id);
if (!empty($id))
$extra[] = "ID=$id";
}
}
if (!empty($extra))
$output->writeln('[' . implode(', ', $extra) . ']');
elseif ($line === true)
$output->writeln("\n$indicator");
else
$output->write($indicator);
static $gc_count = 0;
$gc_count++;
if ($gc_count > 25) {
$gc_count = 0;
gc_collect_cycles();
}
},
'event'
);
I've looked around for a solution to this so I added the gc_collect_cycles() line hoping that would help but it does not resolve the problem.
Looking at the Symfony ConsoleOutput code it is always doing an fopen($outputStream, 'w') but I couldn't find anything where it does close it again.
So you could either try to close it yourself at the end of your function:
$resource = $output->getStream();
fclose($resource);
Or only try to instantiate it once and reuse it then.
NOTE: Actually I think the garbage collection should close it if there is no longer a reference to the anonymous function. Tough I don't know what the static::listen method is doing, so it may be worth a try to close it manually.
The program is creating PDF attachments with and loading pdf files with Zend_Pdf . I know that Zend_Pdf can only work with PDF files equal or lower than 1.4 version.
All files are of 1.3 version. Five pdf attachments are created and attached correctly, but one file is producing an error when loading. I am not sure what is the reason and how to fix it:
Error 1: when files are downgraded to 1.3 version
An error occurred
Application error
Exception information:
Message: Outline childs load error.
Stack trace:
#0 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf\Outline\Loaded.php(345): Zend_Pdf_Outline_Loaded->__construct(Object(Zend_Pdf_Element_Reference), Object(SplObjectStorage))
#1 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf\Outline\Loaded.php(345): Zend_Pdf_Outline_Loaded->__construct(Object(Zend_Pdf_Element_Reference), Object(SplObjectStorage))
#2 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf\Outline\Loaded.php(345): Zend_Pdf_Outline_Loaded->__construct(Object(Zend_Pdf_Element_Reference), Object(SplObjectStorage))
#3 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf\Outline\Loaded.php(345): Zend_Pdf_Outline_Loaded->__construct(Object(Zend_Pdf_Element_Reference), Object(SplObjectStorage))
#4 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf\Outline\Loaded.php(345): Zend_Pdf_Outline_Loaded->__construct(Object(Zend_Pdf_Element_Reference), Object(SplObjectStorage))
#5 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf\Outline\Loaded.php(345): Zend_Pdf_Outline_Loaded->__construct(Object(Zend_Pdf_Element_Reference), Object(SplObjectStorage))
#6 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf\Outline\Loaded.php(345): Zend_Pdf_Outline_Loaded->__construct(Object(Zend_Pdf_Element_Reference), Object(SplObjectStorage))
#7 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf\Outline\Loaded.php(345): Zend_Pdf_Outline_Loaded->__construct(Object(Zend_Pdf_Element_Reference), Object(SplObjectStorage))
#8 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf.php(549): Zend_Pdf_Outline_Loaded->__construct(Object(Zend_Pdf_Element_Reference))
#9 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf.php(317): Zend_Pdf->_loadOutlines(Object(Zend_Pdf_Element_Reference))
#10 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf.php(253): Zend_Pdf->__construct('C:\WebSites\Web...', NULL, true)
#11 C:\WebSites\Web_Applications\workstudy\application\modules\default\models\Students.php(609): Zend_Pdf::load('C:\WebSites\Web...')
#12 C:\WebSites\Web_Applications\workstudy\application\modules\default\controllers\StudentsController.php(262): Model_Students->generateDocuments()
#13 C:\WebSites\Web_Applications\workstudy\library\Zend\Controller\Action.php(513): StudentsController->quizCompletedAction()
#14 C:\WebSites\Web_Applications\workstudy\library\Zend\Controller\Dispatcher\Standard.php(289): Zend_Controller_Action->dispatch('quizCompletedAc...')
#15 C:\WebSites\Web_Applications\workstudy\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#16 C:\WebSites\Web_Applications\workstudy\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#17 C:\WebSites\Web_Applications\workstudy\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#18 C:\WebSites\RSS\Workstudy\index.php(26): Zend_Application->run()
**Error 2: it probably happens when files are not downgraded properly to the lower version **
An error occurred
Application error
Exception information:
Message: Incorrect reference to the object
Stack trace:
#0 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf\Element\Reference.php(128): Zend_Pdf_Element_Reference->_dereference()
#1 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf.php(529): Zend_Pdf_Element_Reference->getType()
#2 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf.php(317): Zend_Pdf->_loadOutlines(Object(Zend_Pdf_Element_Reference))
#3 C:\WebSites\Web_Applications\workstudy\library\Zend\Pdf.php(253): Zend_Pdf->__construct('C:\WebSites\Web...', NULL, true)
#4 C:\WebSites\Web_Applications\workstudy\application\modules\default\models\Students.php(597): Zend_Pdf::load('C:\WebSites\Web...')
#5 C:\WebSites\Web_Applications\workstudy\application\modules\default\controllers\StudentsController.php(262): Model_Students->generateDocuments()
#6 C:\WebSites\Web_Applications\workstudy\library\Zend\Controller\Action.php(513): StudentsController->quizCompletedAction()
#7 C:\WebSites\Web_Applications\workstudy\library\Zend\Controller\Dispatcher\Standard.php(289): Zend_Controller_Action->dispatch('quizCompletedAc...')
#8 C:\WebSites\Web_Applications\workstudy\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#9 C:\WebSites\Web_Applications\workstudy\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#10 C:\WebSites\Web_Applications\workstudy\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#11 C:\WebSites\RSS\Workstudy\index.php(26): Zend_Application->run()
#12 {main}
Php code:
...
$mail = new Zend_Mail();
$mail->setFrom(Zend_Registry::get('config')->app->contact->email);
$mail->addTo($this->getUscEmail(), $this->getFirstName().' '.$this->getLastName());
$mail->addCc(Zend_Registry::get('config')->app->contact->email, 'SOWK FWS');
$mail->setSubject('Workstudy Documentation - '.$this->getFirstName().' '.$this->getLastName());
$content = '......text......';
$mail->setBodyText(strip_tags($content));
$mail->setBodyHtml($content);
...
$file = Zend_Registry::get('config')->app->pdf_path."Foundation Year Students.pdf"; //load pdf from string
$pdf = Zend_Pdf::load($file);
$at1 = $mail->createAttachment($pdf->render());
$at1->filename = "Foundation Year Students steve.pdf";
$at1->type = 'application/pdf';
...
The other way to attach the same file fixed the problem:
$file = Zend_Registry::get('config')->app->pdf_path."Foundation Year Students-Instructions.pdf"; //load pdf from string
$content = file_get_contents($file); // e.g. ("attachment/abc.pdf")
$attachment = new Zend_Mime_Part($content);
$attachment->type = 'application/pdf';
$attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$attachment->encoding = Zend_Mime::ENCODING_BASE64;
$attachment->filename = 'Foundation Year Students-Instructions.pdf'; // name of file
$mail->addAttachment($attachment);
I am working with the UPS api and am having a difficult time debugging. I am getting the following stack trace:
Details
Type: SoapFault
Message: An exception has been raised as a result of client data.
File: /Users/shawn/Documents/work/sites/Wingspan/kaleco/lib/SixString/Utilities/Ups.php
Line: 161
Trace
#0 /Users/shawn/Documents/work/sites/Wingspan/kaleco/lib/SixString/Utilities/Ups.php(161): SoapClient->__soapCall('ProcessShipment', Array)
#1 /Users/shawn/Documents/work/sites/Wingspan/kaleco/routes/ups.php(14): SixString\Utilities\Ups->getShipment()
#2 [internal function]: {closure}()
#3 /Users/shawn/Documents/work/sites/Wingspan/kaleco/vendor/slim/slim/Slim/Router.php(172): call_user_func_array(Object(Closure), Array)
#4 /Users/shawn/Documents/work/sites/Wingspan/kaleco/vendor/slim/slim/Slim/Slim.php(1222): Slim\Router->dispatch(Object(Slim\Route))
#5 /Users/shawn/Documents/work/sites/Wingspan/kaleco/vendor/slim/slim/Slim/Middleware/Flash.php(86): Slim\Slim->call()
#6 /Users/shawn/Documents/work/sites/Wingspan/kaleco/vendor/slim/slim/Slim/Middleware/MethodOverride.php(94): Slim\Middleware\Flash->call()
#7 /Users/shawn/Documents/work/sites/Wingspan/kaleco/vendor/slim/slim/Slim/Middleware/SessionCookie.php(116): Slim\Middleware\MethodOverride->call()
#8 /Users/shawn/Documents/work/sites/Wingspan/kaleco/vendor/slim/slim/Slim/Middleware/PrettyExceptions.php(67): Slim\Middleware\SessionCookie->call()
#9 /Users/shawn/Documents/work/sites/Wingspan/kaleco/vendor/slim/slim/Slim/Slim.php(1174): Slim\Middleware\PrettyExceptions->call()
#10 /Users/shawn/Documents/work/sites/Wingspan/kaleco/public/index.php(6): Slim\Slim->run()
#11 {main}
Here is the block of code:
try{
$mode = array('soap_version' => 'SOAP_1_1', 'trace' => 1,'exceptions' => true );
$client = new \SoapClient($wsdl , $mode);
$client->__setLocation($endpointurl);
$header = new \SoapHeader('http://www.ups.com/XMLSchema/XOLTWS/UPSS/v1.0','UPSSecurity',$this->upss);
$client->__setSoapHeaders($header);
if(strcmp($operation,"ProcessShipment") == 0 ) {
$resp = $client->__soapCall('ProcessShipment',array($this->processShipment()));
echo "Response Status: " . $resp->Response->ResponseStatus->Description ."\n";
//print_r($client->__getLastRequest());
}
else if (strcmp($operation , "ProcessShipConfirm") == 0) {
$resp = $client->__soapCall('ProcessShipConfirm',array($this->processShipConfirm()));
echo "Response Status: " . $resp->Response->ResponseStatus->Description ."\n";
}
else {
$resp = $client->__soapCall('ProcessShipeAccept',array($this->processShipAccept()));
//get status
echo "Response Status: " . $resp->Response->ResponseStatus->Description ."\n";
echo "<pre>";
print_r($resp);
echo "</pre>";
}
}
catch(Exception $ex){
print_r ($ex);
}
Line 161 is in the above code, this is the actual line:
$resp = $client->__soapCall('ProcessShipConfirm',array($this->processShipConfirm()));
I am looking for a way to debug this. It does not appear to be reaching the catch block and I cannot seem to determine the cause of the exception.
Try to catch exception with SoapFault and print its detail property.
try {
$response = $client->$call( $params );
} catch (\SoapFault $fault) {
//trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
var_dump($fault->faultcode);
var_dump($fault->faultstring);
var_dump($fault->detail);
die('Errore chiamata webservice UPS');
}
refer to: http://php.net/manual/en/function.is-soap-fault.php
I don't know the nuances of exception handling in PHP, but Soap exceptions are squirrely little buggers in C# as well. In Visual Studio's debugger, you can get at the details of unhandled exceptions right in the IDE. If you have an option to do this, look for the exception's "detail" XML Element, as this will contain the web service's message telling you what was borked with your request.
As for actually trapping the exception, there's an old but good article by #Jeff Atwood that — though written for (gasp) VB.NET — might still provide some insight into what makes Soap exceptions so, er... slippery: Coding Horror | Throwing better SOAP exceptions
NOTE: For what it's worth, UPS gives this error for bad tracking numbers. Use a good (valid) tracking number and it corrected my issue.
UPS gives this error also for bad ShipFrom/CountryCode or ShipTo/CountryCode in Rates API. e.g. germany can't be rated. This can't found in the UPS dev docs.