Does indices()->refresh() wait for completion? - php

I'm developing a PHP website using Elasticsearch (Official PHP client).
I'm writing tests that need to be sure the newly inserted documents
are ready to search before proceed.
To do this, after indexing new documents, I call:
$client->indices()->refresh()
My question is: Does $client->indices()->refresh() wait for refresh completion before making the PHP script go on? Or does not wait for its completion?
In the second hypothesis, how can make it wait for completion before making PHP test go on?

I know this is not exactly what was asked about refresh() but this is what I do to ensure a document is available to search as soon as it's indexed. I use the ?refresh parameter in the index operation:
$data = [
'type' => 'mytype',
'index' => 'myindex',
'id' => 'thisid',
'refresh' => 'wait_for',
'body' => [ /* document */ ]
];
$client->index($data);

Related

HTML/PHP/SQL - Save a HTML page

Currently I'm working on an application and i have a problem. I want to display an html page but the probem is : there is a lot of data/query behind the page. Is it possible to save the html page with the data every morning and then display the html page saved ? I dont want to load the data every time I load the page because the loading is really long.
I'm working with ZendFramwork and Oracle.
You can use either local storage or session storage for this.
HTML web storage provides two objects for storing data on the client:
window.localStorage - stores data with no expiration date
window.sessionStorage - stores data for one session (data is lost when the browser tab is closed)
Use this link to learn more (https://www.w3schools.com/html/html5_webstorage.asp)
You can use GitHub Pages, write a script in any language to send data in GitHub web page on your decided time and all done your html page in dynamic but act as a static and loads in no time
I think you want to use frontend cache.
There are at least 3 versions of Zend Framework, but the caching si very similar.
For Zend 1 there is some theory https://framework.zend.com/manual/1.12/en/zend.cache.theory.html#zend.cache.clean
Best way is set frontend cache in routes
For that, use this in your router definition file
addRoute($router, [
'url' => "[your-path]",
'defaults' => [
'controller' => '[controller-name]',
'action' => '[action-name]',
'cache' => [TIME-OF-CACHE] // 2 hours = 7200
]
]);
Then, if you really want to delete this cache every morning, you should do it manually, by some CRON script.
For that, try to use this
Zend Framework Clearing Cache
Here is the solution:
You need a cron job that runs the script (the HTML file) every morning
Add ob_start() to beginning of your HTML file
Save the buffer into a file :)
<?php
ob_start();
// Display that HTML file here. You don't need to change anything.
// Add this to the end of your file to output everything into a file.
$out = ob_get_contents();
ob_end_clean();
file_put_contents('cached.html', $out);
?>

Unable to get Browsershot to work with query string parameters

I am running PHP Laravel 5.5.* with spatie/browsershot 3.24 and I am having an issue with pulling the HTML from a url that I generate from a route.
Code:
$url = route('pdfs.plans.results', [
'lang' => $culture->code,
'id' => $id,
'user_id' => \Auth::user()->id,
'pdf-token' => $token->token,
]);
And for now I'm just wanting to dd the raw html generated by this route:
dd(Browsershot::url($url)->bodyHtml());
However, this is failing and it appears to be due to the query parameters in the url string Example url: http://localhost/pdf/plans/results/share?lang=en_US&id=17&user_id=8&pdf-token=PEvWJ7MB7sgQWM9AUfciceL4zNvZrLaSeemGf5J4kGzfOKvaMe8L0FTf32Da
As soon as it hits the second parameter '&id=17' it breaks stating:
'id' is not recognized as an internal or external command
which tells me that NodeJS is what's breaking, I'm guessing the ampersand is throwing it off and it's thinking that I'm passing another command to the console, but I don't know how else to get around this.
Is there a better way to pass the URL, or perhaps an alternative/better way to extract the rendered HTML from a Laravel blade (running VueJS) that I can then use for PDF generation or other business needs?
Thank you!
Maybe windows only related issue as I havent tried it on Linux yet, but I escaped the & and all now works fine.
$url = str_replace('&', '^&', $url)

Is there a serialization format for PHP that I can seek without loading everything?

I have a huge array like this:
array(
'5486215d2f02cc0f257ebda5125486215d2f02c' /* (SHA1) */ => array(
'filename' => 'p_2486433.png',
'directory' => 'aaaac2013'
),
'95b23be7c97d532295b23be7c97d532295b23be' => array(
'filename' => 'p_4857312.png',
'directory' => 'aaaff2013'
),
...
)
Currently I store this as a JSON, which requires me to load the whole structure, a disadvantage it shares with serialize().
Is there a common format that maintains some kind of index so I can seek to the entry I am looking for without loading the whole thing into memory?
I see comments about creating file-based databases however if this doesn't work anyway you might take the larger file and break it into smaller pieces like one record per file and then group with a directory.
Of course there are drawbacks in doing this like flooding your filesystem with a lot of entries that might create some issues on the long run.

Using Codeception functional tests to POST data

I want to create a test which will directly post data to a Laravel page to test it handling bad data.
I can run an acceptance test starting at the page with the form on, call $I->click('Search'); and the page processes the data as expected.
Reading the introduction to Functional Tests on the Codeception website, it states
In simple terms we set $_REQUEST, $_GET and $_POST variables, then we execute your script inside a test, we receive output, and then we test it.
This sounds ideal, set an array of POST data and fire it directly at the processing page. But I can't find any documentation for it. I've played with sendAjaxPostRequest but it's not passing anything to $_POST.
Is there a way I can test the pages in isolation like this?
Turns out the solution lies with the Codeception REST module.
Adding this to the functional.suite.yml file allows you to write:
$I = new TestGuy($scenario);
$I->wantTo('check a page is resistant to POST injection');
$I->sendPOST(
'search',
array(
'startDate' => '2013-07-03',
'endDate' => '2013-07-10',
'exec' => 'some dodgy commands',
));
$I->see('Search results');
$I->dontSee('Dodgy command executed');
A little clunky, but it allows testing of a single page.
From the manual # http://codeception.com/docs/04-AcceptanceTests
$I->submitForm('#update_form', array('user' => array(
'name' => 'Miles',
'email' => 'Davis',
'gender' => 'm'
)));

Routing not working properly on cake

I migrated a cake website from one server to another, but in statics pages is showing a blank page, this is happening in two case scenarios right now
Scenario1:
$this->redirect(Router::url(array('controller' => 'staticpages',
'action' => 'message', 'messageSlug' => 'welcome')));
Scenario2:
$link = Router::url(array('controller' => 'staticpages',
'action' => 'message', 'messageSlug' => 'thanks-for-registering'));
The Facebook PHP SDK is interfering. It's probably throwing an error before Cake can properly redirect (the headers are already sent by groofi__extra_facebook.php.
Have a look what's happening in groofi__extra_facebook.php where the error seems to be stemming from. Probably your new server configuration is missing a vital component, is cURL present, for example?

Categories