-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need absolute path to cache language files #64
Comments
Would you paste your full code snippet here? And where should the cache directory be? |
I don't know which code snippet you mean. It's more than a snippet. I'm testing it on a live server. The only fix applied is the one referred to above. Actually the whole function, as modified, looks like this, because I began by running it on WAMP. From line 30 in File.php:
That seems to be the only way to get a valid path, for me anyway. Apparently all of these files do not receive new data. I uploaded them directly from my WAMP installation on Windows yesterday. mydomain/apps/phpSyllable-master/src/Cache/syllable.it.json Why then is it necessary for them to cache new data? That is what this function does*:
*I haven't changed it. "file_put_contents" requires a full path. |
If you'd like me to, provided Github permits it -- probably not -- I could post a link to the test page on my server. With the error. |
Your question about where the cache directory should be, is kind of throwing me off a little. Correct me, if I'm wrong, please. The cache folder is initially defined in the main page. The demo.php calls it like this:
For my purposes, it's defined:
The only other caching is when the user uploads a file, as opposed to pasting text or html in the form. Here I define a different cache that optionally saves the user's file to the server:
If The point however is that If I can assist, in any way, I'm happy to help. I'd tried a Perl hyphenator first. phpSyllable is orders of magnitude better. Brilliant achievement by Mr. Van Der Lee. |
You need to make sure the phpSyllable cache directory exists. The error of file_put_contents() suggests it does not. Run something like
in the main script somewhere before initialising and using the Syllable object. Note: You should place the Syllable cache in a folder outside of the phpSyllable app folder and not touch the phpSyllable app folder at all, as this makes updates of the package more difficult. |
You're right. Before the initialization is where I should make sure the folder and files exist. Technically, the folder does exist, but on the server for some reason it isn't found, even causing an error. On the other hand, there are threads on "Stack Overflow" among other online communities, that point out that you must pass the exact absolute folder path with filename to The stumbling block for me is that no method at all writes to the folder, error or no error. I take on board your suggestion to move the "cache" folder. I've been in touch with my web-hosting service. They inform me that because the cache folder is not in the publicly accessible area, the files are automatically cached. That, of course, will not do, if the aim is to "update" the *.json files stored in cache. So I am very tempted to move the "cache" folder to the publicly accessible site area. Maybe that will fix something. It would be nice to close this issue. Issues are bad publicity and it might be entirely my fault. Thanks for the reply. |
Use some project file structure like
and have some main.php like
and you will be fine. Note: The path in $cacheDir is an absolute path, as required by file_put_contents(). |
@alexander-nitsche do you think it would be possible for the language update script to also run a version of the Caching to generate files? That would eliminate the need for write permissions for most use cases unless somebody want to provide their own .tex files. |
Hi. To get involved, if I may. There's money in it. If users could upload their own .tex files, or vocabulary lists to splice onto personalized .tex files, it would allow a hyphenation service, maybe for budding e-book authors. Amazon's hyphenation is a disgrace. Authors can do a lot better, if they try to do it manually themselves. At the moment my hosting provider is being stubborn. I haven't even gotten as far as writing/caching *.json files. Moving the "Cache" to the public_html area has helped, but there's still some kind of issue with caching and write permissions. A useful thing I found along the way is that the LibreOffice English hyphenation .tex dictionaries are somewhat better than the existing ones. Should anyone be interested, you can download them from https://github.com/LibreOffice/dictionaries. As soon as (if) I get the *.json caching fixed on my server, I'll post the result. Note the fix, if there is one, wouldn't be applicable to this issue, which is partially only to do with shared hosting. WAMP works great. |
Hi @vanderlee , what do you want to achieve? I am not sure if i could follow here:) Hi @tnbnicer , what do you want to achieve? Who would want to load his/her own tex files? And you can do so now already. You could simply create a specific language files directory, e.g.
Btw: there is already such a hyphenation service at https://syllable.toyls.com/ , which is unfortunately broken currently with console error
|
@alexander-nitsche In the old days people who did hyphenation were called typesetters. Another point. I speculate of course that Amazon's hyphenation is an algorithm. Most probably it is and uses patterns just like we do. |
@vanderlee and @alexander-nitsche, hi.
to:
?? Caching appears to have been behind my server problems. It's fixed. So long as the path is correct, and caching is gone. |
I can close the issue if you want or you can. |
@tnbnicer : Thanks for the details. So you would like to have two features:
<?php
$myCustomLatinHyphenationsInAFrenchText = [
'forum' => ['fo', 'rum'],
'romanum' => ['ro', 'ma', 'num'],
]; |
@tnbnicer : As for integrating the Syllable API into your own project: you should not modify any file of the Syllable package directly, e.g. do not add the cache paths directly into the \Vanderlee\Syllable\Cache\File::filename() method, but do it from outside the package where you instantiate the Syllable object and set the cache path via the cache object, such as. <?php
$remote_ip = "35.214.1.93";
$server = (strpos(getenv( "SERVER_ADDR" ), $remote_ip) !== false) ? "remote" : "local";
$remote = ($server == "remote") ? true : false;
$syllable = new Syllable('nl');
if ($remote) {
$syllable->getCache()->setPath('/home/customer/www/mydomain/apps/phpSyllable-masterTest/src/Cache');
} else {
// do nothing and use default path
} PHP packages are generally meant to be used by instantiating some package objects and executing their API, i.e. their public methods. And you should not set the cache path anywhere inside the syllable package but outside, so rather choose something like if ($remote) {
$syllable->getCache()->setPath('/home/customer/www/mydomain/cache/phpSyllable-masterTest');
} else {
// do nothing and use default path
} and create that path manually or by PHP code (as shown above). And you should not write the full path but make use of the adaptive if ($remote) {
$syllable->getCache()->setPath(__DIR__.'/cache/phpSyllable-masterTest');
} else {
// do nothing and use default path
} This prevents revealing sensitive information and keeps your application flexible. You could probably use the same configuration on your local webserver too, removing the whole local/remote condition: <?php
$syllable = new Syllable('nl');
$syllable->getCache()->setPath(__DIR__.'/cache/phpSyllable-masterTest'); |
@alexander-nitsche Question: would it be possible for the API programmatically to integrate an existing dictionary, say 'en-us.tex', with a customer's uploaded vocabulary list, words to be hyphenated? Example: Alakasandu The customer would also, or only, provide the intended hyphenations, dash separated syllables. Alak-a-sandu See you later. |
@alexander-nitsche Hi, I use a similar array function for exceptions of more than one word, when context determines where the hyphen goes, or the word is shorter than the minimum length. 'Straße' => 'Stra-ße' will not be hyphenated if minimum word length is greater than 6. A longer string was necessary to catch it:
The word 'records' might be a verb or a noun, 're-cords' or 'rec-ords'. Array:
As to the issue at hand -- I'm still stumped by it, by the way -- why wouldn’t the server resolve: "self::$path"? An error. Caching? Writing/generating a new file with caching enabled is pretty useless. The error persists however with caching disabled. Is it an issue or something that my server specifically fumbles at? I don't know. I agree that setting the cache path outside the syllable package is the best approach in general. I apologize for the link above. |
This is a feature request and not supported currently. Would you create an according issue with description and example input and output? |
Have you tried the example codes i posted above? |
@alexander-nitsche
With
I made progress as well on adding hyphenation files (exceptions) uploaded or pasted in a text field. There are most likely various ways to accomplish it. I run LoadLanguage() twice, for the original *.tex file conversion, and again for the exceptions. There is a small error when you do this with 'hyph-de-1996.tex' that reads: Warning: Undefined variable $braces in F:\wamp - 303\www\phpSyllable-masterTest\src\Source\File.php on line 129. What causes it are too many percentage '%' and white space characters at the start of the *.tex file. They have to be deleted. French contains a lot of white space and percentage characters but runs smoothly. ... Again I want to apologize for burdening you with a link. I really appreciate your help. Your suggested solution was right on the button. I feel somewhat embarrassed, and yet happy it works. Thank you. !! |
Update:
Line 66. After I removed the line, the file compiled without a warning.. |
@alexander-nitsche, @vanderlee,
I can't say how -- the
In other words, if
My hosting provider suggests |
Yes, that seems to be correct. The only situations where a cache file is rewritten are (a) if it does not exist or (b) if the cache file read does not match the current cache version or cache file structure. So I am still assuming that your request for an additional set of hyphenation patterns has not yet been implemented and would best fit into a feature request. |
Are you sure? If the file is found to exist?
There is a slight danger involved in rewriting. Online two users might be accessing the same file. If one user chooses a different setting to the other, what would happen? This would be a good time to admit that I made changes to the API that allow a user to personalize the 'minimum hyphen' values. A change to "left minimum", "right minimum" on the client. It works, but since the values are currently read from a cached version of 'syllable.[$language].json' on the server, the updated setting is lost. Note the fix requires changes to the supported version of the API on Github. As a requested feature, it changes too much to be practicable. Otherwise I would request a feature. |
I believe this to be an issue, or at least something that should be looked into.
phpSyllable-master/src/Cache/File.php on line 53:
file_put_contents($file, $this->encode(self::$data));
file_put_contents requires an absolute path. Instead, what it gets is a relative path.
Warning: file_put_contents(/home/customer/www/mydomain/apps/phpSyllable-master/src/cache/syllable.en-us.json): failed to open stream: No such file or directory in /home/customer/www/mydomain/apps/phpSyllable-master/src/Cache/File.php on line 53.
I was able to workaround it by defining an absolute path. File.php.
Note: I'm not sure why 'syllable.en-us.json' must be written to. For developing purposes? As far as I know, the file never changes, except the first time when it is generated.
Also "file_put_contents" works fine with a relative path on Windows WAMPServer. Only in a shared server virtual hosting environment I get an error/warning. If you cannot reproduce the issue, feel free to query.
The text was updated successfully, but these errors were encountered: